Java开发网 |
注册 |
登录 |
帮助 |
搜索 |
排行榜 |
发帖统计
|
您没有登录 |
» Java开发网 » Database/JDBC/SQL/JDO/Hibernate
» MS SQL
打印话题 寄给朋友 订阅主题 |
作者 | Error establishing sock |
debug148
发贴: 16 积分: 0 |
于 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.println; } } } 老是出错,并且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.println; } } } 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 |
已读帖子 新的帖子 被删除的帖子 |
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 |