Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Database/JDBC/SQL/JDO/Hibernate » MS SQL  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 Error establishing sock
debug148





发贴: 16
积分: 0
于 2004-08-24 17:21 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
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;
}
}

}




Eclipse使用技巧

话题树型展开
人气 标题 作者 字数 发贴时间
9590 Error establishing sock debug148 2586 2004-08-24 17:21
7651 Re:Error establishing sock lovefan 36 2004-09-24 15:12
8014 Re:Error establishing sock debug148 17 2004-09-24 22:52
7710 Re:Error establishing sock lovefan 41 2004-11-10 16:37
7486 Re:Error establishing sock waspxyz 24 2004-11-15 22:40
7867 Re:Error establishing sock debug148 52 2004-11-16 10:30
7969 Re:Error establishing sock sanshaoye 133 2004-11-16 11:05
8221 Re:Error establishing sock debug148 90 2004-11-16 15:11

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   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