在连接数据库测试的时候遇到了问题,渴望得到各位的指教,在此拜谢:)
源程序是:
<%@ 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,也已经重启过,可是还是不行...郁闷了~!
希望得到各位的指教,多谢多谢~~~
源程序是:
<%@ 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,也已经重启过,可是还是不行...郁闷了~!
希望得到各位的指教,多谢多谢~~~
/** 以下是连接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;
}
把logger去掉
配置是对的,只不过sa的密码不对,但是在安全性-〉登录-〉sa中直接改不成功,就右击SQL Server服务器-〉属性-〉安全性,将身份验证改为了"SQL Server 和windows",重新设置了密码,就可以了。
多谢各位的指导:)