Reputation: 29
I am trying connect to a database table and getting
java.lang.ClassCastException: oracle.jdbc.driver.T4CStatement cannot be cast to java.beans.Statement
in 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
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