源代码如下:
import java.sql.*;
public class TestSQLServer 
{
public static void main(String[] args)
{
try
{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection con=DriverManager.getConnection("jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=pubs","tom","cat");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from mytable1");

while(rs.next())
{
System.out.println("sid: "+rs.getInt(1));
System.out.println("\tname: "+rs.getString(2).trim());
System.out.println("\tsex: "+rs.getString(3).trim());
System.out.println();
}
rs.close();
stmt.close();
con.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
在安装了SQL Server 2000 Driver for JDBC Service Pack 3以及SQLServer SP4补丁后,并且设置了CLASSPATH并且在JCreator中进行了配置,将那三个jar包都添加到了JDK Profiles中后,结果还是出现了如下异常:
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 TestSQLServer.main(TestSQLServer.java:17)Process completed.然后我进行了对1433端口的测试
用telnet进行1433端口测试后,发现了这个问题(显示结果是):
正在连接到1433...不能打开到主机的连接,在端口23:连接失败我实在是不知道该怎么办了啊!希望高手能够帮帮我
在此多谢各位高手了

解决方案 »

  1.   

    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主【jiangqiuqiu】截止到2008-07-18 16:53:50的历史汇总数据(不包括此帖):
    发帖的总数量:1                        发帖的总分数:0                        每贴平均分数:0                        
    回帖的总数量:0                        得分贴总数量:0                        回帖的得分率:0%                       
    结贴的总数量:0                        结贴的总分数:0                        
    无满意结贴数:0                        无满意结贴分:0                        
    未结的帖子数:1                        未结的总分数:0                        
    结贴的百分比:0.00  %               结分的百分比:---------------------
    无满意结贴率:---------------------无满意结分率:---------------------
    如何结贴请参考这里:http://topic.csdn.net/u/20080501/09/ef7ba1b3-6466-49f6-9d92-36fe6d471dd1.html
      

  2.   

    下载一个新的JDBC驱程试一下,只有一个JAR文件的那个,好像是sqljdbc.jar
      

  3.   

    兄弟,从错误信息来看(Error establishing socket),可能是你的数据库没有打开监听端口,很可能是你的补丁不对,重新安装补丁(SP3或者更高),另外,中文版的Sql Server,则应该安装中文版补丁。
      

  4.   

    另外:中文版SP4补丁地址:http://www.microsoft.com/downloads/details.aspx?displaylang=zh-cn&FamilyID=8E2DFC8D-C20E-4446-99A9-B7F0213F8BC5
      

  5.   

    这个问题今天有人问过了
    http://forum.csdn.net/PointForum/Forum/UserTopicList.aspx?type=TopicUserJoined&_t_=fisbagpx
    你是不是抄袭人家的啊?
      

  6.   

    发错地址了
    问题也是这个问题
    你去这个帖子看看吧
    http://topic.csdn.net/u/20080718/14/59aa2816-37f7-4c87-93f4-fe821d5d39c5.html