日期:2014-05-18  浏览次数:20708 次

jsp 连接sqlserver2000数据库问题
我的连接数据库程序:
public   boolean   connect(){
                try{
                        Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver ").newInstance();
                      String   url= "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=bookstor ";
                      String   user= "sa ";
                        String   password= " ";
                        con=DriverManager.getConnection(url,user,password);
                          stmt=con.createStatement();
        }catch(Exception   ee){System.out.println( "connect   db   error: "+ee.getMessage());
                        return   false;
                }
            return   true;
        }

程序在运行时老连接不上数据库,调试结果为:
ee:   java.lang.Exception   =   {java.sql.SQLException@1977} "java.sql.SQLException:   [Microsoft][SQLServer   2000   Driver   for   JDBC]Error   establishing   socket. "
SQLState:   java.lang.String   =   {java.lang.String@1981} "08001 "
vendorCode:   int   =   0
next:   java.sql.SQLException   =   {java.sql.SQLException@1982} "java.sql.SQLException:   [Microsoft][SQLServer   2000   Driver   for   JDBC]Connection   refused:   connect "
detailMessage:   java.lang.String   =   {java.lang.String@1983} "[Microsoft][SQLServer   2000   Driver   for   JDBC]Error   establishing   socket. "
cause:   java.lang.Throwable   =   {java.sql.SQLException@1977} "java.sql.SQLException:   [Microsoft][SQLServer   2000   Driver   for   JDBC]Error   establishing   socket. "
stackTrace:   java.lang.StackTraceElement[]   =   null

请问这个是什么方面的错误(本人刚学jsp)

------解决方案--------------------
你的SQL SERVER2000 打补丁了没?
给个地址:

SQL Server2000 Service Pack 3a 补丁 中文版

http://www.vnit.cn/dongyi/Soft/zzkf/shujuku/200609/447.html
------解决方案--------------------
LZ你进入CMD netstat -an检查1433端口是否开启,没有的话, 首先检查SQL SERVER的端口是不是使用1433,然后检查防火墙是不是屏蔽1433端口,都没问题 打SP3 OR SP4补丁 微软官方就能下盗版的也能用 下载时看清楚你需要的补丁因为 SP3 SP4补丁分好几种功能补丁。
------解决方案--------------------
个人感觉这2个地方除了问题:
con=DriverManager.getConnection(url,user,password);
stmt=con.createStatement();
首先,con是什么呀?你要定义啊!同理,stmt也是一样。
修改为:
Connection con=DriverManager.getConnection(url,user,password);
Statement stmt=con.createStatement();
好象是这样吧,改了再试
------解决方案--------------------
SQLServer 2000 沒有打補丁