Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1531180
  • 博文数量: 3500
  • 博客积分: 6000
  • 博客等级: 准将
  • 技术积分: 43870
  • 用 户 组: 普通用户
  • 注册时间: 2008-05-03 20:31
文章分类

全部博文(3500)

文章存档

2008年(3500)

我的朋友

分类:

2008-05-04 20:24:24

一起学习
以下我写的用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) 好发愁,还请高手指点一二,先谢了。 下载本文示例代码


JDBC数据库连接的问题JDBC数据库连接的问题JDBC数据库连接的问题JDBC数据库连接的问题JDBC数据库连接的问题JDBC数据库连接的问题JDBC数据库连接的问题JDBC数据库连接的问题JDBC数据库连接的问题JDBC数据库连接的问题JDBC数据库连接的问题JDBC数据库连接的问题
阅读(83) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~