| JDBC数据库连接的问题 |
| |
发布者: 发布时间:2007-09-23 |
|
|
|
以下我写的用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)
好发愁,还请高手指点一二,先谢了。
|
| (转载文章请保留出处:北天JAVA技术网(www.java114.com)) |
| |
| 更多精彩文章: |
| Hibernate的事务和并发(ZT) |
| 用JavaBean编写SQLServer数据库连接类 |
| Java数据库编程中的基本步骤和常用技巧 |
| 使用技巧:简单介绍JSP数据库高级操作 |
| 使用JDBC建立各种数据库的连接方式集萃 |
| 线程控制动画 |
| |
| 最近评论: |
|
|
| 鍥炲 |
|
|
|
| 那个雨天的想法! |
| wow gold,wow power leveling.wow power leveling,wow power leveling,
max(8175) |
|
|
| max sa nv nei |
| maxmaxmaxmaxmaxmaxmaxmaxmaxmaxmaxmax
|
|
|
| max sa nv nei |
| maxmaxmaxmaxmaxmaxmaxmaxmaxmaxmaxmax
|
|
|
| max sa nv nei |
| maxmaxmaxmaxmaxmaxmaxmaxmaxmaxmaxmax
|
|
|
| max sa nv nei |
| maxmaxmaxmaxmaxmaxmaxmaxmaxmaxmaxmax
|
|
|
| max sa nv nei |
| maxmaxmaxmaxmaxmaxmaxmaxmaxmaxmaxmax
|
|
|
| 如果真的有来生! |
| 四川旅游,九寨沟旅游,稻城亚丁旅游,四姑娘山旅游,海螺沟旅游,西藏旅游,
max(3313) |
|
|
| 那天的情景! |
| Maple Story mesos,MapleStory mesos,ms mesos,mesos,SilkRoad Gold,
max(2003) |
|
|
| 轻轻走过你的窗前! |
| world of warcraft gold,cheap world of warcraft gold,warcraft gold,world of warcraft gold,cheap world of warcraft gold,warcraft gold, max(2839) |
|
|
| |
| 免责声明:该文章由网友发表,如果对您造成侵权,请联系站长。 |