1

我正在尝试连接到数据库表并进入 java.lang.ClassCastException: oracle.jdbc.driver.T4CStatement cannot be cast to java.beans.Statementoracle 10g express edition

        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));
        }
4

1 回答 1

4

con.createStatement()应该返回一个实现java.sql.Statement而不是java.beans.Statement.

也许您导入java.beans.Statement而不是java.sql.Statement导致演员阵容失败?

于 2013-08-03T13:14:34.317 回答