请大家帮帮忙,不胜感激!SQL2000  打过SP4补丁;3个jar包msbase.jar,mssqlserver.jar,msutil.jar3个jar包msbase.jar,mssqlserver.jar,msutil.jar也有;
代码如下(是数据库的连接,查询,更新,关闭操作):
import java.util.List;
import java.sql.*;
import java.util.ArrayList;import com.wsy.model.BookInfo;
import com.wsy.model.BookType;
import com.wsy.model.Operater;
import com.wsy.model.User;
public class Dao {
protected static String dbClassName="com.microsoft.jdbc.sqlserver.SQLServerDriver"; //定义驱动包名
protected static String dbUrl="jdbc:microsoft:sqlserver://localhost:1433;" 
+"DatabaseName=db_librayr;SelectMethod=Cursor";  //定义数据库连接路径
protected static String dbUser="sa";  //定义数据库连接用户名
protected static String dbPwd="";  //定义数据库连接密码
protected static String second=null;
protected static Connection conn=null;  //定义一个数据库连接

private Dao(){
try{ //捕捉数据库连接异常
if(conn==null){ //如果数据库连接为空
Class.forName(dbClassName).newInstance(); //装载SQL Server驱动
conn=DriverManager.getConnection(dbUrl, dbUser, dbPwd);          //获取数据库连接

}else //如果连接不为空
return;
}catch(Exception e){
e.printStackTrace();
}
}

/* 创建执行查询语句的方法 executeQuery */
private static ResultSet executeQuery(String sql){
try{ //捕捉数据库操作异常
if(conn==null) //数据库连接如果为空
new Dao(); //调用Dao方法连接数据库
return conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE).executeQuery(sql);
//返回一个ResultSet结果集
} catch(SQLException e){ //捕捉异常
e.printStackTrace();
return null;
}
}

/*创建执行更新操作的方法 executeUpdate() */
private static int executeUpdate(String sql){
try{
if(conn==null)
new Dao();
return conn.createStatement().executeUpdate(sql); //进行数据库更新操作
}catch (SQLException e){
System.out.println(e.getMessage()); //打印捕捉的异常
return -1;
}
}

/*创建数据库关闭方法*/
public static void close(){
try{
conn.close(); //关闭数据库连接
}catch(SQLException e){
e.printStackTrace();
}finally{
conn=null; //最终将数据库连接置空
}
}
提示是:java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSConnection.<init>(Unknown Source)
at com.microsoft.jdbc.sqlserver.SQLServerImplConnection.open(Unknown Source)
at com.microsoft.jdbc.base.BaseConnection.getNewImplConnection(Unknown Source)
at com.microsoft.jdbc.base.BaseConnection.open(Unknown Source)
at com.microsoft.jdbc.base.BaseDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at com.wsy.dao.Dao.<init>(Dao.java:26)
at com.wsy.dao.Dao.executeQuery(Dao.java:39)
at com.wsy.dao.Dao.check(Dao.java:77)
at com.wsy.iframe.BookLoginIFrame$BookLoginAction.actionPerformed(BookLoginIFrame.java:33)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at com.wsy.dao.Dao.executeQuery(Dao.java:40)
at com.wsy.dao.Dao.check(Dao.java:77)
at com.wsy.iframe.BookLoginIFrame$BookLoginAction.actionPerformed(BookLoginIFrame.java:33)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

解决方案 »

  1.   

    1433端口开了没
    看你的SQL网络实用工具里
    协议上的TCP/IP的端口有没有开,是不是1433
      

  2.   

    是的,服务器网络实用工具和客户端网络实用工具中的TCP/IP端口全是1433
      

  3.   

    也是这个程序,也是这个问题.......
    什么都试过了,什么端口1433,什么三个Jar包,什么环境变量,还有什么混合模式数据库,什么构建路径、、、、
    等等都试过了,还是不行,好晕啊!!!!