日期:2014-05-18  浏览次数:20854 次

学习用JDBC访问SQL2000,大家帮我只要显示就好,test.jsp
<%@   page   contentType= "text/html;charset=gb2312 "   language= "java "   import= "java.sql.*,java.io.* "%>
<%
    try{
        Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver ").newInstance();
        Connection   conn   =   java.sql.DriverManager( "jdbc:microsoft:sqlserver://127.0.0.1:8181;DtatbaseName=red ", "sa ", "sunwei ");
        Statement   stmt   =   conn.createStatement();
        ResultSet   rs   =   stmt.executeQuery( "select   *   from   test; ");
        while(rs.next()){
            out.println(rs.getString( "name "));
            out.println(rs.getString( "userid "));
        }
        rs.close();
        stmt.close();
        conn.close();
    }
    catch(Exception   e){
      e.printStackTrace();
    }
  %>

帮我看看错在哪了?

------解决方案--------------------
Connection conn = java.sql.DriverManager( "jdbc:microsoft:sqlserver://127.0.0.1:8181;DtatbaseName=red ", "sa ", "sunwei ");

改成
Connection conn = java.sql.DriverManager.getConnection( "jdbc:microsoft:sqlserver://127.0.0.1:8181;DtatbaseName=red ", "sa ", "sunwei ");
------解决方案--------------------
去掉SQL语句的分号

ResultSet rs = stmt.executeQuery( "select * from test; ");
改为
ResultSet rs = stmt.executeQuery( "select * from test ");
------解决方案--------------------
你的sql server改过端口吗?默认是1433
------解决方案--------------------
可能你的包没导入。
可能你改了分号之后没有重新发布。