Topic: 不能连上数据库!! |
![]() |
1.不能连上数据库!! | Copy to clipboard |
Posted by: james19790619 Posted on: 2005-06-02 22:56 import java.sql.*; public class testRoll { public static void main(String [] args) { String url="jdbc:microsoft:sqlserver://localhost:1433;"+"DatabaseName=xscj"; Connection con; Statement st; try { Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); } catch(ClassNotFoundException e) { System.out.println("Driver can't be loaded"); System.out.println(e.getMessage()); } String username="sa"; String password="001301"; try { con=DriverManager.getConnection(url,username,password); st=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY); ResultSet rs=st.executeQuery("SELECT * FROM XS"); rs.absolute(4); int rowNum=rs.getRow(); System.out.println("rowNum:\t"+rowNum); rs.relative(-3); rowNum=rs.getRow(); System.out.println("rowNum:\t"+rowNum); rs.absolute(1); System.out.println("after last?"+rs.isAfterLast()); if(!rs.isAfterLast()) { int nID=rs.getInt("学号"); String strName=rs.getString(" 姓名"); System.out.println("id:"+nID+"\tname:"+strName); } rs.close(); st.close(); con.close(); } catch(SQLException se) { System.out.println("SQLException:"+se.getMessage()); } } } |
2.Re:不能连上数据库!! [Re: james19790619] | Copy to clipboard |
Posted by: why Posted on: 2005-06-02 23:43 What's the error message? |
3.Re:不能连上数据库!! [Re: james19790619] | Copy to clipboard |
Posted by: james19790619 Posted on: 2005-06-03 23:01 在Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");出现异常 显示 Driver can't be loaded com.microsoft.jdbc.sqlserver.SQLServerDriver SQLException:NO suitable driver |
4.Re:不能连上数据库!! [Re: james19790619] | Copy to clipboard |
Posted by: why Posted on: 2005-06-03 23:13 ![]() i.e. Class Not Found make sure that the 3 M$ JDBC jars are in the classpath. |
5.Re:不能连上数据库!! [Re: james19790619] | Copy to clipboard |
Posted by: why Posted on: 2005-06-05 06:14 Deleted post: http://www.cjsdn.net/post/view?bid=1&id=146007 SQLException:[Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket. 为什么? Please do a search on this Database board. http://www.cjsdn.net/post/search |
![]() |
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 |