在连接数据库测试的时候遇到了问题,渴望得到各位的指教,在此拜谢:)
源程序是:
<%@ 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=pubs";
          //pubs 为你的数据库的
          String user="sa";
          String password="admin";
          Connection con= DriverManager.getConnection(url,user,password);
          Statement stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
          String sql="select job_id,job_desc from jobs";
          ResultSet rst=stmt.executeQuery(sql);
          while(rst.next()) { %>
                您的第一个字段内容为:<%=rst.getString(1)%><br>
                您的第二个字段内容为:<%=rst.getString(2)%><br>
       <% } %>
       <% out.print("数据库操作成功,恭喜你"); %>
       <% rst.close();
          stmt.close();
          con.close();
       %>
       </body>
       </html>
存放在C:\Tomcat 5.0\webapps\ROOT下。
输入http://127.0.0.1:8080/sql_test.jsp后出现以下问题: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][SQLServer]?? 'sa' ???????: ???? SQL Server ??????
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:867)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:800)
org.apache.jsp.sql_005ftest_jsp._jspService(sql_005ftest_jsp.java:86)
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][SQLServer]?? 'sa' ???????: ???? SQL Server ??????
com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
com.microsoft.jdbc.sqlserver.tds.TDSRequest.processErrorToken(Unknown Source)
com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReplyToken(Unknown Source)
com.microsoft.jdbc.sqlserver.tds.TDSLoginRequest.processReplyToken(Unknown Source)
com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReply(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.sql_005ftest_jsp._jspService(sql_005ftest_jsp.java:55)
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.--------------------------------------------------------------------------------
SP4也已经下载安装了,驱动程序msbase.jar、mssqlserver.jar、msutil.jar也已经复制到C:\Tomcat 5.0\common\lib,也已经重启过,可是还是不行...郁闷了~!
希望得到各位的指教,多谢多谢~~~

解决方案 »

  1.   

    http://blog.chinaunix.net/u/21684/showart_270377.html
      

  2.   

    使用sql server提供的jdbc驱动有时候会出现一些错误。 改用jtds-0.6.jar链接SqlServer吧。
      

  3.   

    把msbase.jar、mssqlserver.jar、msutil.jar放在C:\Tomcat 5.0\webapps\ROOT\WEB-INF\lib下还是不行,老问题,郁闷~~PS:谢谢两位的指导:)
      

  4.   

    我使用的是Tomcat 6.0,把那三个文件放在C:\Tomcat 6.0\lib下试试,我测试没问题哦。
      

  5.   

    String   password="admin"; //你确认密码是admin?
      

  6.   

    用下面的代码看看
    /** 以下是连接MSSQL数据库 */
    public static Connection getMsSqlConnection() {
    String url = "jdbc:microsoft:sqlserver://127.0.0.1;DatabaseName=pubs";
    String driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
    String uid = "sa";
    String pwd = "sa";
    try {
    Class.forName(driver);
    } catch (ClassNotFoundException ex) {
    if (logger.isDebugEnabled()) {
    logger.debug("getMsSqlConnection() - 装载驱动时出错!"
    + ex.getMessage());
    }
    }
    try {
    conn = DriverManager.getConnection(url, uid, pwd);
    } catch (SQLException ex1) {
    if (logger.isDebugEnabled()) {
    logger.debug("getMsSqlConnection() - 得到连接时出错"
    + ex1.getMessage());
    }
    }
    return conn;
    }
      

  7.   

    配置信息不要改
    把logger去掉
      

  8.   

    我用的是Tomcat5.5,我一般是把msbase.jar、mssqlserver.jar、msutil.jar放在C:\Tomcat 5.0\common\lib下面
      

  9.   

    如果驱动jar配置不对会报装载驱动时出错!" 
      

  10.   

    把驱动的三个jar放在你的工程的web-inf/lib/ 下
      

  11.   

    然后确定你的classpath配置没有出错
      

  12.   

    多谢各位,我的问题终于解决了~
    配置是对的,只不过sa的密码不对,但是在安全性-〉登录-〉sa中直接改不成功,就右击SQL Server服务器-〉属性-〉安全性,将身份验证改为了"SQL Server 和windows",重新设置了密码,就可以了。
    多谢各位的指导:)