Topic: JDBC连接SQLSERVER数据库出错。请大家帮忙 |
Print this page |
1.JDBC连接SQLSERVER数据库出错。请大家帮忙 | Copy to clipboard |
Posted by: huajiazhou Posted on: 2005-04-05 12:01 原程序如下: <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>连接数据库的例子</title> </head> <body> 以下是从MS SQLserver数据库中读出的数据:<hr> <table border="1"> <tr><td>id</td><td>书名</td><td>出版社</td><td>价格</td></tr> <%! String trans(String chi) { String result=null; byte temp[]; try { temp=chi.getBytes("iso-8859-1"); result=new String(temp); } catch(UnsupportedEncodingException e) { System.out.println(e.toString()); } return result; } %> <% Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance(); String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=jspdev"; String USER="sa"; String PWD="5696285"; Connection con= DriverManager.getConnection(url,USER,PWD); Statement stmt=con.createStatement(); String inq="select * from book"; ResultSet rst=stmt.executeQuery(inq); while(rst.next()) { out.println("<tr>"); out.println("<td>"+trans(rst.getString("bookId"))+"</td>"); out.println("<td>"+trans(rst.getString("bookName"))+"</td>"); out.println("<td>"+trans(rst.getString("publisher"))+"</td>"); out.println("<td>"+rst.getFloat("price")+"</td>"); out.println("<tr>"); } rst.close(); stmt.close(); con.close(); %> </table> </body> </html> 以下是错误提示: type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception javax.servlet.ServletException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket. org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825) org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758) org.apache.jsp.testMssql2_jsp._jspService(testMssql2_jsp.java:118) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94) javax.servlet.http.HttpServlet.service(HttpServlet.java:810) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:298) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236) javax.servlet.http.HttpServlet.service(HttpServlet.java:810) 请大家帮我看看这到底是什么问题!数据库的用户名跟密码绝对没错!JDBCFORSQLSERVER驱动放到了LIB文件夹里面了!数据库里面有我连接的这个数据库!多谢 |
2.Re:JDBC连接SQLSERVER数据库出错。请大家帮忙 [Re: huajiazhou] | Copy to clipboard |
Posted by: huajiazhou Posted on: 2005-04-05 14:35 怎么没人帮我啊!我搞这个搞了几天了就这个问题让我一直不能前进 HELP!!!! |
3.Re:JDBC连接SQLSERVER数据库出错。请大家帮忙 [Re: huajiazhou] | Copy to clipboard |
Posted by: sogui Posted on: 2005-04-05 16:07 String inq="select * jspdev"; 这一句是什么意思?是不是你粗心少写了“FROM YOU TABLE”?这一个SQL语句有错? |
4.Re:JDBC连接SQLSERVER数据库出错。请大家帮忙 [Re: huajiazhou] | Copy to clipboard |
Posted by: huajiazhou Posted on: 2005-04-05 16:47 不好意思!那是笔误,现在已经改过来了 但是还是有这个错误提示 帮帮我吧! |
5.Re:JDBC连接SQLSERVER数据库出错。请大家帮忙 [Re: huajiazhou] | Copy to clipboard |
Posted by: why Posted on: 2005-04-05 19:33 try the JDBC connection with a console program first. make sure that port 1433 is not blocked -- there could be an issue with Win XP SP2. |
6.Re:JDBC连接SQLSERVER数据库出错。请大家帮忙 [Re: huajiazhou] | Copy to clipboard |
Posted by: huajiazhou Posted on: 2005-04-05 23:29 oh!god my OS is just win xp sp2!!! please tell me what can i do ?? thank u very much!! |
7.Re:JDBC连接SQLSERVER数据库出错。请大家帮忙 [Re: huajiazhou] | Copy to clipboard |
Posted by: alexwish Posted on: 2005-04-06 10:28 winxp 打了sp2后需要设置然后才能连接sql 2k,具体如何设置你可以google一下。 |
8.Re:JDBC连接SQLSERVER数据库出错。请大家帮忙 [Re: huajiazhou] | Copy to clipboard |
Posted by: huajiazhou Posted on: 2005-04-06 12:32 大哥能告诉我具体设置哪里吗 ?我找了没找到! 我刚学这个时间不长! 已经三天没进展了 |
9.Re:JDBC连接SQLSERVER数据库出错。请大家帮忙 [Re: huajiazhou] | Copy to clipboard |
Posted by: huajiazhou Posted on: 2005-04-06 19:42 javax.servlet.ServletException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket 这个错误主要是什么引起的啊 ?有人遇到过这样的问题吗 ?? |
10.Re:JDBC连接SQLSERVER数据库出错。请大家帮忙 [Re: huajiazhou] | Copy to clipboard |
Posted by: 西北狼 Posted on: 2005-04-19 00:11 我也遇到同一问题,端口我也改了几个,本没用的是2000服务器版的操作系统~~ 还是不行啊怎么回事呢?还有编写的JSP只能读数据库的数据而不能更改, 为啥?请版主帮助~再此谢过~~~ |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |