Topic: [求助]JSP连接SQL Server 2000问题,看了很多资料还未解决,求救! |
Print this page |
1.[求助]JSP连接SQL Server 2000问题,看了很多资料还未解决,求救! | Copy to clipboard |
Posted by: langfanyun11 Posted on: 2006-03-24 11:00 本机环境:WinXP +SP2 JDK1.5.0 Tomcat5.0.16 SQL Server 2000(XP下能用的那种版本) 已装了SQL Server 2000 Driver for JDBC Service Pack 3,并且已经把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中去。 JDK和Tomcat 测试后都能正常运行,JavaBean,Servlet都测试能正常运行。 用于测试连接数据库的代码如下: <%-- 使用JDBC驱动直接访问SQLServer2000数据库. --%> <%@ page contentType = "text/html; charset = gb2312" language = "java" import = "java.sql.*" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd" > <html> <head> <title> use JDBC to connect SQL Server </title> <style type = "text/css"> <!-- .style{ color:#FF0000; font-size:24px; } --> </style> </head> <body> <div align = "center" ><span class = "style1" > JDBC access SQL Server directly </span><BR></div> <hr><br> <table border = 2 bordercolor = "#FF0000" align = "center"> <tr> <td> au_id </td> <td> au_lname </td> <td> au_fname </td> <td> phone </td> <td> address </td> <td> city </td> <td> state </td> <td> zip </td> <td> contract </td> <tr> <% Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver" ).newInstance(); String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName = pubs"; String user = "yc"; String password = "123"; Connection conn = DriverManager.getConnection( url, user, password ); Statement stmt = conn.createStatement( ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE ); String sql = "SELECT TOP 10 * FROM authors"; ResultSet rs = stmt.executeQuery( sql ); while( rs.next() ){ %> <tr> <td><%= rs.getString( "au_id" ) %></td> <td><%= rs.getString( "au_lname" ) %></td> <td><%= rs.getString( "au_fname" ) %></td> <td><%= rs.getString( "phone" ) %></td> <td><%= rs.getString( "address" ) %></td> <td><%= rs.getString( "city" ) %></td> <td><%= rs.getString( "state" ) %></td> <td><%= rs.getString( "zip" ) %></td> <td><%= rs.getString( "contract" ) %> </tr> <%}%> <% out.print( "Congratulations, The access is successful!" ); rs.close(); stmt.close(); conn.close(); %> </table> </body> </html> (该程序在其他机器上运行后能连上数据库) JSP页面提示错误信息为: 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:867) org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:800) org.apache.jsp.test.E6_jsp._jspService(E6_jsp.java:87) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133) javax.servlet.http.HttpServlet.service(HttpServlet.java:856) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248) javax.servlet.http.HttpServlet.service(HttpServlet.java:856) 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.(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(Unknown Source) java.sql.DriverManager.getConnection(Unknown Source) org.apache.jsp.test.E6_jsp._jspService(E6_jsp.java:47) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133) javax.servlet.http.HttpServlet.service(HttpServlet.java:856) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248) javax.servlet.http.HttpServlet.service(HttpServlet.java:856) note The full stack trace of the root cause is available in the Tomcat logs. -------------------------------------------------------------------------------- Apache Tomcat/5.0.16 本人刚开始学习JSP,请高手帮帮忙,谢谢先~~~~~~~~~ |
2.Re:[求助]JSP连接SQL Server 2000问题,看了很多资料还未解决,求救! [Re: langfanyun11] | Copy to clipboard |
Posted by: langfanyun11 Posted on: 2006-03-24 11:07 补充:MS SQL Server 2000已装SP4 补丁! |
3.Re:[求助]JSP连接SQL Server 2000问题,看了很多资料还未解决,求救! [Re: langfanyun11] | Copy to clipboard |
Posted by: langfanyun11 Posted on: 2006-03-24 15:40 有人吗??? |
4.Re:[求助]JSP连接SQL Server 2000问题,看了很多资料还未解决,求救! [Re: langfanyun11] | Copy to clipboard |
Posted by: bigbigpoo Posted on: 2006-03-24 16:16 要不你试试看,不要写localhost,改成你机器的名字。同时,再把那个1433端口改一下,用其它的端口试试。 |
5.Re:[求助]JSP连接SQL Server 2000问题,看了很多资料还未解决,求救! [Re: langfanyun11] | Copy to clipboard |
Posted by: why Posted on: 2006-03-24 21:05 check the topmost posts in our Database/JDBC/JDO board, e.g. http://www.cjsdn.net/post/view?bid=10&id=164530 |
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 |