Topic: JDBC链接SQL SERVER2000的问题?脑爆了!! |
Print this page |
1.JDBC链接SQL SERVER2000的问题?脑爆了!! | Copy to clipboard |
Posted by: 蓝眼龙 Posted on: 2005-11-05 19:54 代码:<%@ page contentType="text/html;charset=gb2312"%> <%@ page import="java.sql.*"%> <html> <body> <%Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance(); String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=text"; //pubs为你的数据库的 //String user="sa"; //String password=""; Connection conn= DriverManager.getConnection(url,"sa",""); Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE); String sql="select * from q"; ResultSet rs=stmt.executeQuery(sql); while(rs.next()) {%> 您的第一个字段内容为:<%=rs.getString(1)%> 您的第二个字段内容为:<%=rs.getString(2)%> <%}%> <%out.print("数据库操作成功,恭喜你");%> <%rs.close(); stmt.close(); conn.close(); %> </body> </html> 错误提示: 500 Servlet Exception 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.open(Unknown Source) at com.microsoft.jdbc.base.BaseDriver.connect(Unknown Source) at java.sql.DriverManager.getConnection(DriverManager.java:512) at java.sql.DriverManager.getConnection(DriverManager.java:171) at _c__jsp._jspService(/c.jsp:10) at com.caucho.jsp.JavaPage.service(JavaPage.java:75) at com.caucho.jsp.Page.subservice(Page.java:506) at com.caucho.server.http.FilterChainPage.doFilter(FilterChainPage.java:182) at com.caucho.server.http.Invocation.service(Invocation.java:315) at com.caucho.server.http.CacheInvocation.service(CacheInvocation.java:135) at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:246) at com.caucho.server.http.HttpRequest.handleConnection(HttpRequest.java:163) at com.caucho.server.TcpConnection.run(TcpConnection.java:139) at java.lang.Thread.run(Thread.java:534) 但是,把localhost换成192.168.1.4(本地IP)居然成功了,但变回localhost就又失败了!搞了好久都不知道为什么!大侠帮帮我吧!!T_T!! |
2.Re:JDBC链接SQL SERVER2000的问题?脑爆了!! [Re: 蓝眼龙] | Copy to clipboard |
Posted by: why Posted on: 2005-11-06 04:48 > ping localhost and let us know the result Which OS are you using? |
3.Re:JDBC链接SQL SERVER2000的问题?脑爆了!! [Re: 蓝眼龙] | Copy to clipboard |
Posted by: 蓝眼龙 Posted on: 2005-11-07 09:04 我的操作系统是WIN2000 Pro 不知搞了什么,现在用localhost行了!真的搞不懂!!谢谢各位了!! |
4.Re:JDBC链接SQL SERVER2000的问题?脑爆了!! [Re: 蓝眼龙] | Copy to clipboard |
Posted by: dlq Posted on: 2005-11-07 23:15 你是咋个解决的? 我也出现上面一样的问题 |
5.Re:JDBC链接SQL SERVER2000的问题?脑爆了!! [Re: 蓝眼龙] | Copy to clipboard |
Posted by: q_yuan Posted on: 2005-11-15 11:33 要不你改一下SQL客户端端口,不使用1433 |
6.Re:JDBC链接SQL SERVER2000的问题?脑爆了!! [Re: q_yuan] | Copy to clipboard |
Posted by: why Posted on: 2005-11-15 18:43 q_yuan wrote: What's the purpose of using another port? Or is it your wild guess? |
7.Re:JDBC链接SQL SERVER2000的问题?脑爆了!! [Re: 蓝眼龙] | Copy to clipboard |
Posted by: yingzhe Posted on: 2005-11-16 13:17 同问,我郁闷两天了 装完jdk,tomcat,配置后,运行正常 下载安装jdbc for sqlserver,msbase.jar,mssqlserver.jar,msutil.jar拷贝到Tomcat目录下common\lib目录下,之后,修改环境变量中的CLASSPATH, 把SQL Server 2000 For JDBC 驱动程序安装目录下的 C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib\msbase.jar;C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib\mssqlserver.jar; C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib\msutil.jar;追加到CLASSPATH中去 测试连接数据库的程序如下 <%@ page contentType="text/html;charset=gb2312"%> <%@ page import="java.lang.*, java.io.*, java.sql.*, java.util.*"%> <html> <body> <% Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance(); String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=netclass"; //我在数据库中新建了一个netclass数据库 //sa的密码是:123 Connection conn=DriverManager.getConnection(url,"sa","123"); Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE); String sql="select * from Student"; //netclass中有个Student表 ResultSet rs=stmt.executeQuery(sql); while(rs.next()) {%> 您的第一个字段内容为:<%=rs.getString(1)%> 您的第二个字段内容为:<%=rs.getString(2)%> <%}%> <%out.print("数据库操作成功,恭喜你");%> <%rs.close(); stmt.close(); conn.close(); %> </body> </html> 错误提示: HTTP Status 500 - -------------------------------------------------------------------------------- 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:846) org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:779) org.apache.jsp.netclass.test_jsp._jspService(test_jsp.java:87) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94) javax.servlet.http.HttpServlet.service(HttpServlet.java:802) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324) 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:802) root cause java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket. com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source) com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source) com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source) com.microsoft.jdbc.sqlserver.tds.TDSConnection.<init>(Unknown Source) com.microsoft.jdbc.sqlserver.SQLServerImplConnection.open(Unknown Source) com.microsoft.jdbc.base.BaseConnection.getNewImplConnection(Unknown Source) com.microsoft.jdbc.base.BaseConnection.open(Unknown Source) com.microsoft.jdbc.base.BaseDriver.connect(Unknown Source) java.sql.DriverManager.getConnection(DriverManager.java:512) java.sql.DriverManager.getConnection(DriverManager.java:171) org.apache.jsp.netclass.test_jsp._jspService(test_jsp.java:53) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94) javax.servlet.http.HttpServlet.service(HttpServlet.java:802) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324) 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:802) 两天了,一直都没有解决这个问题 不知道楼主是怎么解决的 焦急等待中ing....... |
8.Re:JDBC链接SQL SERVER2000的问题?脑爆了!! [Re: 蓝眼龙] | Copy to clipboard |
Posted by: yingzhe Posted on: 2005-11-16 13:28 另注: 我的os是xp sp2 ping localhost 的结果如下: >ping localhost Pinging yjw2187 [127.0.0.1] with 32 bytes of data: Reply from 127.0.0.1: bytes=32 time<1ms TTL=128 Reply from 127.0.0.1: bytes=32 time<1ms TTL=128 Reply from 127.0.0.1: bytes=32 time<1ms TTL=128 Reply from 127.0.0.1: bytes=32 time<1ms TTL=128 Ping statistics for 127.0.0.1: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 0ms, Maximum = 0ms, Average = 0ms 望各位高手不吝赐教 焦急中ing....... |
9.Re:JDBC链接SQL SERVER2000的问题?脑爆了!! [Re: 蓝眼龙] | Copy to clipboard |
Posted by: 迸泉 Posted on: 2005-11-20 17:36 你去给SQLServer2000打个SP3的补丁就OK了,端口一般不会冲突,我用的也是XP sp2,我就是这样解决的。那个补丁网上到处都有下的,可以去微软下,不过它的补丁是英文版的,不支持中文版SQLserver2000 |
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 |