JSP虚拟主机,jsp空间,java空间,java虚拟空间JSP虚拟主机,jsp空间,java空间,java虚拟空间

JDBC数据库连接的问题



作者:    文章来源:
发布日期:2007年01月04日
以下我写的用JDBC连接sql server数据库的代码,不知道是哪的错,请高手指点:

一个连接数据库的Bean
package mypack;
import java.sql.*;

public class Link
{
String sDriver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
String connUrl = "jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=pubs"; //这里最好动态加载数据库名称
String user = "sa";
String pwd = "";
private Connection conn = null;
ResultSet rs = null;

public Link() throws Exception //连接数据库
{
try{
Class.forName(sDriver);
conn = DriverManager.getConnection(connUrl,user,pwd);
}
catch(java.lang.ClassNotFoundException e)
{
System.err.println(e.getMessage());
}
}

public ResultSet executeQuery(String sql)
{
ResultSet rst = null;
try
{
Statement stmt = conn.createStatement();
rst= stmt.executeQuery(sql);
}
catch (SQLException e)
{
System.err.println(e.getMessage());
}
return rst;
}
}


在网页里使用上面的bean:
<%@ page language = "java" import = "java.sql.*"%>





<%
String queryStr = "SELECT * FROM authors";
String queryResult;
ResultSet RS = Sqlx.executeQuery(queryStr);

/*while(RS.next())
{
out.println(RS.getString("au_lname"));
}*/
RS.close();
%>




运行时出现以下的错:
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][SQLServer]?? 'sa' ???????: ???? SQL Server ??????
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)
org.apache.jsp.sqlforjsp_jsp._jspService(sqlforjsp_jsp.java:77)
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][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)
mypack.Link.(Link.java:17)
org.apache.jsp.sqlforjsp_jsp._jspService(sqlforjsp_jsp.java:51)
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)


好发愁,还请高手指点一二,先谢了。

Copyright © 2002-2012 JSPCN.net. All rights reserved.
JSP中文网    备案号:粤ICP备09171188号
成都恒海科技发展有限公司    成都市一环路南二段6号新瑞楼三楼8号