为什么我安装了Microsoft的jdbc驱动for SQL Server ,环境变量也设了,还是不行呢?抛出的例外为:com.microsoft.jdbc.sqlserver.SQLServerDriver 代码如下:<%@ page contentType="text/html;charset=gb2312"%>    
<%@ page import="java.sql.*"%> 
<html>    
<body>    
<%
try
{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=jspdb"; //pubs为你的数据库的 
String user="sa"; 
String password=""; 
Connection conn= DriverManager.getConnection(url,user,password); 
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE); 
String sql="select * from test"; 
ResultSet rs=stmt.executeQuery(sql); 
while(rs.next()) 
{%> 
您的第一个字段内容为:<%=rs.getString(1)%> 
您的第二个字段内容为:<%=rs.getString(2)%> 
<%}%> 
<%
out.print("数据库操作成功,恭喜你");
%> 
<%rs.close(); 
stmt.close(); 
conn.close(); 
}catch(Exception e)
{
out.println(e.getMessage());
}   
%>    
</body>    
</html> 谁能告诉我?

解决方案 »

  1.   

    开始——程序——管理工具——ODBC数据源,在那里设置数据源,并且把(假设你的Web服务器是Tomcat)SQL Server for JDBC 目录下的lib目录中的三个.jar文件拷贝到Tomcat目录下common目录下的lib目录中
      

  2.   

    j2me_home(魔·天使)  你好。你说的是通过odbc连接数据库么?我是个初学者,不是很懂。是不是可以不通过odbc呢?应该怎么设置?
      

  3.   

    whzhaha(风之子)  你好。请问你说的数据源是什么,怎么弄?
      

  4.   

    大哥们啊,人家是直连的阿,跟odbc有啥关系阿。
    俺估计是驱动包有问题。
    你的错误吗,再贴全点来看看
      

  5.   

    xiaopeipei2004(小裴)  你好。出错的消息我这里没有,你说是驱动包的问题,有那些可能呢?连接SQL Server数据库,都应该有哪些设置呢?
      

  6.   

    错误提示是这样的: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]Error establishing socket.
    org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)
    org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)
    org.apache.jsp.ASP.index_jsp._jspService(index_jsp.java:315)
    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]Error establishing socket.
    com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
    com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
    com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
    com.microsoft.jdbc.sqlserver.tds.TDSConnection.<init>(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.ASP.index_jsp._jspService(index_jsp.java:221)
    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)
      

  7.   

    msbase.jar, mssqlserver.jar, msutil.jar拷贝到Tomcat目录下common\lib目录下
    或者root\WEB-INF\lib,重新启动tomcat
      

  8.   

    xiaopeipei2004(小裴)  谢谢你,我回去试一下。
      

  9.   

    msbase.jar, mssqlserver.jar, msutil.jar拷贝到jdk\jre\lib\ext里!我试过可以的.