连接sql server 2000报错!求助!!
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import
java.sql.SQLException;
import java.sql.Statement;
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
} catch (
ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Connection cn;
try {
cn = DriverManager.getConnection("jdbc:microsoft:sqlserver://127.0.0.1:1433;databaseName=master","","");
Statement st = cn.createStatement();
ResultSet rs = st.executeQuery("Select * FROM MSreplication_options");
while(rs.next())
{
for(int i = 0; i <= 7; i++)
{
System.out.println(rs.getString(i+1));
}
}
rs.close();
} catch (
SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
//
//
//
cn = DriverManager.getConnection("jdbc:microsoft:sqlserver://127.0.0.1:1433;databaseName=master","","");
这句报错,
报错信息是:
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.cloudcloud.soft.Test.main(Test.java:33)
求救!!!!
------解决方案--------------------
出现这个错误的原因可能有很多,你需要确认你本地是否安装成功了sqlserver.同时还要确认sqlserver的服务是否启动了.占用的端口号是否是1433.在命令行下用netstat -a 命令查看一下.看1433端口是否开启.如果没有开启,那服务应该没有启动,或者端口错误.
------解决方案--------------------如果你是第一次连接的话建议还是重装下sqlserver