package lianjiejing;
import java.sql.*;
public class lianjie {
private Statement smt;
private Connection con;
public lianjie()
{
try
{
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs";
String user="sa";
String password="";
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
Connection conn= DriverManager.getConnection(url,user,password);
if(con!=null)
{
System.out.println("ok");
}
}catch(Exception e)
{
e.printStackTrace();
}
}
public static void main(String[] args) {
lianjie lianjie = new lianjie();
}
异常为:
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 lianjiejing.lianjie.<init>(lianjie.java:15)
at lianjiejing.lianjie.main(lianjie.java:27)
谁帮我看看是怎么回事,弄好久了都不知道哪错了,谢谢了