问题:MSSQL在服务器端网络实用工具中修改了1433的端口,改成其他5001,但仍然出错
的系统是windowsXP sp2,已经打了sp4的补丁(Microsoft JDBC sp4补丁),已经关闭了防火墙,在注册表中查看tcp的tcpport,和修改的5001是一致的(通过服务器端网络实用工具修改了端口,改成5001),无论是本机连还是其他机连,都连接不上(应该是一直在尝试在连吧?)
使用netstat -an没有发现5001的端口
下面是使用5001的端口:
代码
public class DatabaseConn {
public Connection Connection(){
Connection conn = null;
try {
Class.forName(DataUtil.SQL_DRIVER).newInstance();
conn = DriverManager.getConnection(DataUtil.SQL_URL,DataUtil.SQL_USERNAME,DataUtil.SQL_PASSWD);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}catch(IllegalAccessException e){
e.printStackTrace();
}catch(InstantiationException e){
e.printStackTrace();
}catch(SQLException e){
e.printStackTrace();
}
return conn;
}
}
属性:
代码
public class DataUtil {
/**
* 用户名
*/
public static final String SQL_USERNAME = "sa ";
/**
* 密码
*/
public static final String SQL_PASSWD = "ldjc ";
/**
* sql server 的驱动
*/
public static final String SQL_DRIVER = "com.microsoft.jdbc.sqlserver.SQLServerDriver ";
/**
* sql server 的url
* jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=XZXK
* localhost填目标地址
*/
public static final String SQL_URL = "jdbc:microsoft:sqlserver://172.18.3.174:5001;DatabaseName=master ";
}
测试:
代码
public class test {
DatabaseConn con = new DatabaseConn();
public void testConnection(){
System.out.println( "1 ");
Connection conn = con.Connection();
System.out.println( "2 ");
PreparedStatement pstmt = null;
ResultSet rs = null;
String temp = null;
try {
conn.setAutoCommit(false);
} catch (SQLException e) {
e.printStackTrace();
}
String sql = "select * from t_ShouLi ";
try {
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
while(rs.next()){
temp = rs.getString( "YWLSH ");
System.out.println(temp);
}
} catch (SQLException e) {
e.printStackTrace();
}
}
public static void main(String[] args){
test p = new test();
p.testConnection();
}
}
异常:
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 com.startdragon.zwxt.ldjc.connect.DatabaseConn.Connection(DatabaseConn.java:20)
at com.startdragon.zwxt.ldjc.test.testConnection(test.java:16)
at com.startdragon.zwxt.ldjc.test.main(test.java:40)
Exception in thread "main " java.lang.NullPointerException
at com.startdragon.zwxt.ldjc.test.testConnection(test.java:21)
at com.startdragon.zwxt.ldjc.test.main(test.java:40)
如果是使用系统已开的端口 2030,则
上面的输出是:1 (一直还在connect的状态),请问这是怎么回事?[code]
[解决办法]
通过服务器端网络实用工具修改了端口为5001后还需要通过客户端网络实用工具修改了端口5001
必须是成对出现的
[解决办法]
改了,但问题还是一样
[解决办法]
SQL Server打补丁没?