Java开发网 |
注册 |
登录 |
帮助 |
搜索 |
排行榜 |
发帖统计
|
您没有登录 |
» Java开发网 » Servlet/JSP/JSF/JavaFX Script
打印话题 寄给朋友 订阅主题 |
作者 | [求助]JSP连接SQL Server 2000问题,看了很多资料还未解决,求救! |
langfanyun11
发贴: 3 |
于 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,请高手帮帮忙,谢谢先~~~~~~~~~ 关于Jute Forum的长期发展给官方的建议 |
话题树型展开 |
人气 | 标题 | 作者 | 字数 | 发贴时间 |
2141 | [求助]JSP连接SQL Server 2000问题,看了很多资料还未解决,求救! | langfanyun11 | 5178 | 2006-03-24 11:00 |
1627 | Re:[求助]JSP连接SQL Server 2000问题,看了很多资料还未解决,求救! | langfanyun11 | 30 | 2006-03-24 11:07 |
1595 | Re:[求助]JSP连接SQL Server 2000问题,看了很多资料还未解决,求救! | langfanyun11 | 6 | 2006-03-24 15:40 |
1660 | Re:[求助]JSP连接SQL Server 2000问题,看了很多资料还未解决,求救! | bigbigpoo | 55 | 2006-03-24 16:16 |
1674 | Re:[求助]JSP连接SQL Server 2000问题,看了很多资料还未解决,求救! | why | 109 | 2006-03-24 21:05 |
已读帖子 新的帖子 被删除的帖子 |
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 |