JDBC数据库连接的问题

以下我写的用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:











运行时出现以下的错:
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)


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值