Toushif Nadaf
Toushif Nadaf

Reputation: 29

Getting ClassCastException in oracle 10g express edition.

I am trying connect to a database table and getting java.lang.ClassCastException: oracle.jdbc.driver.T4CStatement cannot be cast to java.beans.Statementin oracle 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));
        }

Upvotes: 1

Views: 1014

Answers (1)

micha
micha

Reputation: 49602

con.createStatement() should return an implementation of java.sql.Statement and not of java.beans.Statement.

Maybe you imported java.beans.Statement instead of java.sql.Statement which causes the cast to fail?

Upvotes: 4

Related Questions