2013-08-03 80 views
1

我試圖連接到一個數據庫表,獲取 java.lang.ClassCastException: oracle.jdbc.driver.T4CStatement cannot be cast to java.beans.Statement在Oracle 10g Express版在Oracle 10g express版本中獲取ClassCastException。

 Class.forName("oracle.jdbc.driver.OracleDriver"); 
     System.out.println("Driver loaded."); 

     Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","toushif"); 
     System.out.println("Connection Established."); 
     String sql = "SELECT * FROM TOUSHIF"; 

     Statement st = (Statement) con.createStatement(); 
     ResultSet rs = ((java.sql.Statement) st).executeQuery(sql); 

     while(rs.next()) 
     { 
      System.out.println(rs.getString(1)); 
     } 
+0

你正在得到什麼類型的錯誤? –

回答

3

con.createStatement()應返回java.sql.Statement的實現,而不是java.beans.Statement

也許你是進口java.beans.Statement而不是java.sql.Statement導致鑄件失效?