我的jsp环境是jdk+tomcat5.0+sql server 2000(个人版),在winxp系统下。我打开sql server 2000企业管理器,在microsoft sql server ——》(local)(Windows NT) ——》数据库 下建立了一个数据库叫jspsql,在这个数据库下面新建了一个表叫student:
id 姓名 学号 专业 性别
1 张三 123 计算机 男
2 李四 456 化学 男
3 李琴 789 数学 女
请问我怎么才能把这张表里的所有数据读取到一张jsp页面中去????(我用jdbc驱动连接,不要用jdbc-odbc桥接器)
jdbc驱动也已经安装好了,然后我用了如下代码jdbc.jsp:
<%@page import="java.lang.*, java.io.*, java.sql.*, java.util.*" contentType="text/html;charset=gb2312"%> 
<html> 
<body> 
<%Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance(); 
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=jspsql"; 
String user="sa"; 
String password="123456"; 
Connection conn= DriverManager.getConnection(url,user,password); 
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE); 
String sql="select * from student"; 
ResultSet rs=stmt.executeQuery(sql); 
while(rs.next())
       {
       
             out.print(rs.getInt("id")); 
             out.print("<br>"); 
             out.print(rs.getString("姓名"));
             out.print("<br>"); 
             out.print(rs.getString("学号"));
             out.print("<br>"); 
             out.print(rs.getString("专业"));
             out.print("<br>"); 
             out.print(rs.getString("性别"));
        }%>
<%out.print("数据库连接成功,恭喜你");%> 
<% 
rs.close(); 
stmt.close(); 
conn.close(); 
%> 
</body> 
</html> 
但是出现错误了,错误代码如下:
HTTP Status 500 - --------------------------------------------------------------------------------type Exception reportmessage 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.testsql.jdbc_jsp._jspService(jdbc_jsp.java:89)
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.testsql.jdbc_jsp._jspService(jdbc_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)
note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs.
给个例子行吗?谢谢……

解决方案 »

  1.   

    LZ为什么google一下啊:http://www.blogjava.net/lpeter/archive/2006/12/22/89501.html
      

  2.   

    看下端口...
    jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=jspsql
    这个写的是不是SQL Server2000的它和SQL Server2005的不一样。
    jar包也是一样,不要搞成2005的了!
      

  3.   

    Error establishing socket.分明是没连接上!
      

  4.   

    数据库连接出错了.查看jar文件有没有问题,看看端口是否禁用
      

  5.   

    javax.servlet.ServletException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket
    自己慢慢调试的