我的SQL数据库为什么连接不上呢?
我写了个java程序,连接 SQL Server数据库。可老是有异常,我又看不懂,哪位大虾能给点意见啊!小弟谢谢了!!import java.sql.*;
public class JDBCExample{
public static void main(String args[]){
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433; DatabaseName=master","sa","");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from student");
while(rs.next()){
System.out.print("学号: " + rs.getInt(1));
System.out.print("\t姓名: " + rs.getString(2));
System.out.print("\t性别: " + rs.getInt(3));
System.out.println("\t年龄: " + rs.getString(4));
}
rs.close();
stmt.close();
conn.close();
}catch(Exception e){
e.printStackTrace();
}
}
}
下面的是异常信息:
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:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at test.JDBCExample.main(JDBCExample.java:9)