/*********************************************** /* /*DBTest.Java /* /******************************************* */ import java.sql.*; public class DBTest { Connection con; Statement sta; ResultSet rs; String driver; String url; String user; String pwd; public DBTest() { driver = "com.microsoft.jdbc. sqlserver.SQLServerDriver";; url = "jdbc:microsoft:sqlserver: //localhost:1433;DatabaseName =test"; //test為數據庫名 user = "sa"; pwd = "sa"; //請更改為你相應的用戶和密碼 init(); } public void init() { try{ Class.forName(driver); System.out.println("driver is ok"); con = DriverManager. getConnection(url,user,pwd); System.out.println("conection is ok"); sta = con.createStatement(); rs = sta.executeQuery ("select * from room"); while(rs.next()) System.out.println (rs.getInt("roomNum")); }catch(Exception e) { e.printStackTrace(); } } public static void main(String args[]) //自己替換[] { new DBTest(); } }
driver is ok java.sql.SQLException: [Microsoft] [SQLServer 2000 Driver for JDBC] Error establis hing socket. at com.microsoft.jdbc.base. BaseExceptions.createException(Unknown Source ) 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:523) at java.sql.DriverManager. getConnection(DriverManager.java:171) at DbTest.init(DbTest.java:32) at DbTest.<init>(DbTest.java:25) at DbTest.main(DbTest.java:46) Press any key to continue...
driver is ok conection is ok java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC] [SQLServer]對 象名 'room' 無效。 at com.microsoft.jdbc.base. BaseExceptions.createException(Unknown Source ) at com.microsoft.jdbc.base. BaseExceptions.getException(Unknown Source) at com.microsoft.jdbc.sqlserver.tds. TDSRequest.processErrorToken(Unknown Source) at com.microsoft.jdbc.sqlserver.tds. TDSRequest.processReplyToken(Unknown Source) at com.microsoft.jdbc.sqlserver.tds. TDSExecuteRequest.processReplyToken( Unknown Source) at com.microsoft.jdbc.sqlserver.tds. TDSRequest.processReply(Unknown Sour ce) at com.microsoft.jdbc.sqlserver. SQLServerImplStatement.getNextResultType (Unknown Source) at com.microsoft.jdbc.base. BaseStatement.commonTransitionToState (Unknown Source) at com.microsoft.jdbc.base. BaseStatement.postImplExecu te(Unknown Source) at com.microsoft.jdbc.base. BaseStatement.commonExecute(Unknown Source) at com.microsoft.jdbc.base. BaseStatement.executeQueryInternal (Unknown So urce) at com.microsoft.jdbc.base. BaseStatement.executeQuery(Unknown Source) at DbTest.init(DbTest.java:35) at DbTest.<init>(DbTest.java:25) at DbTest.main(DbTest.java:46) Press any key to continue...
driver is ok conection is ok 1001 1002 1003 1004 1005 1006 Press any key to continue...
關鍵詞: