当前位置: 代码迷 >> J2SE >> 连接sqlserver 出错解决方法
  详细解决方案

连接sqlserver 出错解决方法

热度:158   发布时间:2016-04-24 16:06:53.0
连接sqlserver 出错



Exception   in   thread   "main "   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(DriverManager.java:525)
at   java.sql.DriverManager.getConnection(DriverManager.java:171)
at   datatest.DataTest.main(DataTest.java:16)


=======================================
package   datatest;
import   java.sql.DriverManager;
import   java.sql.*;
import   java.sql.SQLException;
import   java.sql.Connection;
import   java.sql.Statement;
import   java.sql.ResultSet;
import   java.lang.*;
import   javax.swing.JOptionPane;
public   class   DataTest   {
public   static   void   main(String   []   args )   throws   ClassNotFoundException,   SQLException
{       JOptionPane.showInputDialog( "start ");
        Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver ");
        JOptionPane.showInputDialog( "connection+++ ");
 
final   Connection   con   =   DriverManager.getConnection( "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=fabu; ", "sa "   , " ");

Statement   statement=con.createStatement();
ResultSet   set=statement.executeQuery( "select   *   from   cg ");

JOptionPane.showInputDialog( "ok ");
}

}


------解决方案--------------------
1.如果是xp系统的话要把sqlserver的sp4补丁给打上才能打开1433端口。。。
2.加载sqlserver的jdbc的三个驱动包
------解决方案--------------------
应该是没有打sp3补丁的原因。
  相关解决方案