Topic: 请教:连接SQL Server2000时出错 |
Print this page |
1.请教:连接SQL Server2000时出错 | Copy to clipboard |
Posted by: k704790 Posted on: 2004-11-29 21:28 小弟最近写了一个连接MS SQL的测试程序,编译时没有错,可是运行时一行出现错误,不知哪位大哥可以帮一下小弟,代码如下: package myClass.simon; //import myClass.simon.*; import java.sql.*; /** * * @author k704790 */ public class MyConnectionSQL { public MyConnectionSQL() { } public static void main(String args[]){ //SQLServerConnectionFactory ConnFactory = null; //JdbcOdbcConnectionFactory ConnFactory = null; Connection conn = null; Statement stmt = null; ResultSet rs = null; String mySQL = "select job_id,job_desc from dbo.jobs"; System.out.println("这是一个显示SQL数据库连接的例子:"); //ConnFactory = new SQLServerConnectionFactory("localhost",1433,"simon","sa",""); /*try { ConnFactory = new SQLServerConnectionFactory("localhost",1433,"simon","sa","sa"); //ConnFactory = new JdbcOdbcConnectionFactory("LocalServer"); ConnFactory.setUserName("sa"); ConnFactory.setPassword("sa"); } catch(Exception e) { System.out.println("初始化出现异常!"); return; } System.out.println("DriverName: " + ConnFactory.getDriverName()); System.out.println("URL: " + ConnFactory.getUrl()); System.out.println("UserName: " + ConnFactory.getUserName()); System.out.println("Password: " + ConnFactory.getPassword()); */ try { //conn = ConnFactory.getConnection(); Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); } catch(ClassNotFoundException e) { System.out.println("Can't find class"); return; } try { conn = DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=simon;User=sa;Password=sa"); //stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY); stmt = conn.createStatement(); rs = stmt.executeQuery(mySQL); } catch(SQLException e) { System.out.println("Error when return resultset"); return; } catch(Exception e) { System.out.println("Error:"); e.printStackTrace(); return; } try { System.out.println("Return resultset: "); System.out.println("1." + rs.getString("job_desc")); } catch(Exception e) { System.out.println("显示结果出错!"); } 错误如下: Error when return resultset |
2.Re:请教:连接SQL Server2000时出错 [Re: k704790] | Copy to clipboard |
Posted by: xhxasdf Posted on: 2004-12-08 14:40 System.out.println("DriverName: " + ConnFactory.getDriverName()); System.out.println("URL: " + ConnFactory.getUrl()); System.out.println("UserName: " + ConnFactory.getUserName()); System.out.println("Password: " + ConnFactory.getPassword()); */ ?? 顺便把javaBean也看看撒!! |
3.Re:请教:连接SQL Server2000时出错 [Re: k704790] | Copy to clipboard |
Posted by: k704790 Posted on: 2005-01-01 22:45 不解? |
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 |