Topic: Error establishing sock

  Print this page

1.Error establishing sock Copy to clipboard
Posted by: debug148
Posted on: 2004-08-24 17:21

import java.sql.*;
import java.io.*;
public class shujuku{
public static void main(String[] args)
{
try{
   System.out.println("start");

Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
System.out.println("end");

String url="jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=student;SelectMethod=cursor";

String user = "sa";
String password = "wx520jie";
Connection conn = DriverManager.getConnection(url,user,password);
Statement stmt = conn.createStatement();
String sql = "SELECT * FROM student where num=3";
ResultSet rs = stmt.executeQuery(sql);
while(rs.next()){
String name=rs.getString(2);
System.out.println(name);
System.out.print("has success");
}
rs.close();
stmt.close();
conn.close();
}
catch(Exception e){
System.err.printlnEnvelope;
}
}

}

老是出错,并且jdbc-sqlserver2000的驱动也装了.并且classpath也配置了。我用的windows2003,jdk,编辑环境是:textpad
错误如下:
start
end
java.sql.SQLException: [Microsoft][SQLServer JDBC Driver]Error establishing sock
et.
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 Sou
rce)
at com.microsoft.jdbc.base.BaseConnection.getNewImplConnection(Unknown S
ource)
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:512)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at DatabaseName.main(DatabaseName.java:16)
请按任意键继续. . .

但是换成jdbc-odbc驱动就可以了。郁闷,不知道为什么?用jdbc-odbc桥的代码在下面:
import java.sql.*;

public class shujuku{
public static void main(String[] args)
{
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc:odbc:student";
String user = "sa";
String password = "wx520jie";
Connection conn = DriverManager.getConnection(url,user,password);
Statement stmt = conn.createStatement();
String sql = "SELECT * FROM student where num=3";
ResultSet rs = stmt.executeQuery(sql);
while(rs.next()){
String name=rs.getString(2);
System.out.println(name);
}
rs.close();
stmt.close();
conn.close();
}
catch(Exception e){
System.err.printlnEnvelope;
}
}

}

2.Re:Error establishing sock [Re: debug148] Copy to clipboard
Posted by: lovefan
Posted on: 2004-09-24 15:12

你是不是在本地机器用执行的程序?电脑没有接到局域网,而是单独的一个机器?

3.Re:Error establishing sock [Re: debug148] Copy to clipboard
Posted by: debug148
Posted on: 2004-09-24 22:52

是的,你知道什么原因?给讲讲。谢谢

4.Re:Error establishing sock [Re: debug148] Copy to clipboard
Posted by: lovefan
Posted on: 2004-11-10 16:37

不好意思,我很少来这个论坛。

今天刚来才发现有悄悄话,不知道你的问题解决没有

5.Re:Error establishing sock [Re: debug148] Copy to clipboard
Posted by: waspxyz
Posted on: 2004-11-15 22:40

你的Sql Server是不是没有升级到sp3!

6.Re:Error establishing sock [Re: debug148] Copy to clipboard
Posted by: debug148
Posted on: 2004-11-16 10:30

Sql Server升级到sp3了呀,就连jdbc都生级到sp3了。
是不是我用的是2003的问题?

7.Re:Error establishing sock [Re: debug148] Copy to clipboard
Posted by: sanshaoye
Posted on: 2004-11-16 11:05

reinstall your sp3

While you install sp3, have a choice, you must choice it,but I can't remember that clearly, try to search here.

8.Re:Error establishing sock [Re: debug148] Copy to clipboard
Posted by: debug148
Posted on: 2004-11-16 15:11

While you install sp3, have a choice, you must choice it?
怎么改变?改变哪个?我是一路默认下去的!能给详细讲一下吗?谢谢


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923