jsp sql连接套接字错误mysql server 2008 R2

时间:2013-04-08 11:37:16

标签: java sql-server jsp

我随机收到以下错误你们可以帮我解决这个问题????

请注意错误开始之下的线路。

  

[在   org.apache.jsp.jsp.getBookingUserSlots_jsp._jspService(org.apache.jsp.jsp.getBookingUserSlots_jsp:275)]


Error in dboperation getBookingUserSlots.jsp.............java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.
Error in dboperation getBookingUserSlots.jsp.............[Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.
    at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
    at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
    at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
    at com.microsoft.jdbc.sqlserver.tds.TDSConnection.<init>(Unknown Source)
    at com.microsoft.jdbc.sqlserver.SQLServerImplConnection.open(Unknown Source)
    at com.microsoft.jdbc.base.BaseConnection.getNewImplConnection(Unknown Source)
    at com.microsoft.jdbc.base.BaseConnection.getImplConnection(Unknown Source)
    at com.microsoft.jdbc.base.BaseStatement.setupImplConnection(Unknown Source)
    at com.microsoft.jdbc.base.BaseStatement.<init>(Unknown Source)
    at com.microsoft.jdbc.base.BasePreparedStatement.<init>(Unknown Source)
    at com.microsoft.jdbc.base.BaseConnection.prepareStatement(Unknown Source)
    at com.microsoft.jdbc.base.BaseConnection.prepareStatement(Unknown Source)
    at org.apache.jsp.jsp.getBookingUserSlots_jsp._jspService(org.apache.jsp.jsp.getBookingUserSlots_jsp:275)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:99)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:325)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
    at LoginFilter.doFilter(LoginFilter.java:46)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:541)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
    at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
    at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
    at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
    at java.lang.Thread.run(Unknown Source)

String driverName111 = (String) arrLstSQLServer.get(3); 

将从context.xml返回以下代码

<drivername>com.microsoft.jdbc.sqlserver.SQLServerDriver</drivername>    

这就是我的file.jsp的样子

<html>
  <head>
    <base href="<%=basePath%>">

    <title>Booking Agent Virtual Labs</title>

    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">


  </head>
   <body>

<%              
HashMap hmReadXML11=new HashMap();
citbook.ReadDBSolveITXml solveitXML11=new citbook.ReadDBSolveITXml();
hmReadXML11 = solveitXML11.hmXML;
ArrayList arrLstSQLServer  = (ArrayList) hmReadXML11.get("mssqlserver");
String userName = (String) arrLstSQLServer.get(0);
String userPassword = (String) arrLstSQLServer.get(1);              
String url = (String) arrLstSQLServer.get(2)+";databaseName=DBNAME;user="+userName+";password="+userPassword;
String driverName111 = (String) arrLstSQLServer.get(3); 
if(userPassword==null){
    userPassword="";
}
userPassword = userPassword.trim();
Class.forName(driverName111).newInstance();
con11 = DriverManager.getConnection (url, userName, userPassword);                              
%>
</body>

</html>

用户名和密码从

中读取

context.xml中

<mssqlserver>
    <username>xxxxx</username>
    <password>xxxxxxx</password>
    <url>jdbc:sqlserver://192.168.X.XXX\DBINSTANCE:1305</url>
    <drivername>com.microsoft.jdbc.sqlserver.SQLServerDriver</drivername>
</mssqlserver>

1 个答案:

答案 0 :(得分:0)

我猜你使用的是错误的驱动程序:

Error in dboperation getBookingUserSlots.jsp.............[Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.

看看:Microsoft SQL Server JDBC Driver 3.0它支持SQLServer2008R2


以下行返回什么:

String driverName111 = (String) arrLstSQLServer.get(3);

为什么得到(3)?