日期:2014-05-18  浏览次数:20753 次

高分求助java访问server2000问题!急急急!在线等!
我的代码如下:

import   java.sql.*;  


class   insert  

{  

public   static   void   main(String[]   args)  

{  

String   url= "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=news ";  

try  

{  
Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver ");  
Connection   con=DriverManager.getConnection(url, "news ", "news ");  
Statement   stmt=con.createStatement();  
stmt.close();  
con.close();  
}  

catch(SQLException   ex)  

{  

ex.printStackTrace();  

}  

catch(java.lang.Exception   ex)  

{  

ex.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:525)
at   java.sql.DriverManager.getConnection(DriverManager.java:171)
at   insert.main(insert.java:19)
系统sp3和sp4补丁都打了!
jdbc驱动也装了!
请高手指教!解决马上就给50分!

------解决方案--------------------
我遇到过类似的问题,肯定是sp3没安上,建议你在看看,我这里有测试是否连上的源码 如下:
import java.sql.*;

public class DBManager{
Connection conn=null;
public DBManager(){
try{
Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver ");
}catch(Exception e){
System.out.println( "类加载失败 ");
}
try{
String url= "jdbc:microsoft:sqlserver://localhost:1433;databaseName=university ";//连接本机的1433端口,数据库名称university
conn = DriverManager.getConnection(url, "sa ", "aaaqqq123 ");//连接数据库用的用户名为sa,密码为空
System.out.println( "OK! ");
}catch(Exception e){
System.out.println( "数据库连接失败 ");
e.printStackTrace();
}
}
public static void main(String arg[]){
DBManager db=new DBManager();
}
}
还有一个问题,就是测试的前提要开启tomcat服务器,你配了没有
------解决方案--------------------
String url= "jdbc:microsoft:sqlserver://localhost:1433;databaseName=(university) ";//用你自己的数据库名
conn = DriverManager.getConnection(url, "sa ", "(aaaqqq123) ");//用你自己sqlserver的密码
注意我的括号