简单的数据库连接问题
源码:
package dbconn;
import java.sql.*;
public class Getconn {
private static final String dbDriver= "com.microsoft.jdbc.sqlserver.SQLServerDriver ";
private static final String url= "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=message_board ";
private static final String userName= "sa ";
private static final String password= "sa ";
private static Connection conn=null;
public Getconn() {
try {
System.out.println( "dbDriver======== "+dbDriver);
Class.forName(dbDriver).newInstance();
System.out.println( "注册成功! ");
} catch (
InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (
IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (
ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
System.out.println( "url=============== "+url);
System.out.println( "userName========= "+userName);
System.out.println( "password======== "+password);
conn=DriverManager.getConnection(url, userName, password);
System.out.println( "连接成功! ");
} catch (
SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public Connection getconn(){
return conn;
}
public static void main(String args[]) throws IllegalAccessException, InstantiationException, Class
NotFoundException{
Getconn connnn=new Getconn();
Connection conn=connnn.getconn();
}
}
出现的问题:
dbDriver
注册成功!
url===============jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=message_board
userName=========sa
password========sa
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)