wood burning stoves 2.0*
The moose likes JDBC and the fly likes java.lang.ClassCastException error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "java.lang.ClassCastException error" Watch "java.lang.ClassCastException error" New topic
Author

java.lang.ClassCastException error

seema prakash
Ranch Hand

Joined: Nov 17, 2004
Posts: 59
I am trying to store a word document in Oracle database.
I am using Oracle9i. But, I get the error as:

java.lang.ClassCastException
I tried creating a querystring, qstring like
String qString = "select resume from Resumes where emp_id = 9004 for update";
oracle.jdbc.driver.OracleResultSet ors = (OracleResultSet)stat.executeQuery(qString);
res.next();
BLOB blob = ors.getBLOB("resume");

But, it was of no help. I've included the code below. I've marked the place where the error is shown. Please help. Thanks in advance.

[ March 14, 2005: Message edited by: seema prakash ]
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
It doesn't look like you're using an oracle driver:

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");


What jdk version are you using? java.sql.ResultSet has a getBlob() method
in 1.4.2: ResultSet API
seema prakash
Ranch Hand

Joined: Nov 17, 2004
Posts: 59
Now I connect to the oracle driver by issuing the following statement:

conn = DriverManager.getConnection("jdbc racle:thin:@localhost:2030 rcl","SYSTEM","password");



But, the error now is:
java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getConnection(DriverManager.java:532)
at java.sql.DriverManager.getConnection(DriverManager.java:171)

I am compiling the code using NetBeans IDE which supports JDK1.4 and higher versions and the JDK installed with Oracle9i is JDK 1.3. Does this have to do something with the error?
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
Do you have an oracle driver?

I have an oracle 9i client installed and in the jdbc/lib directory there are some driver jars.

Or you may be able to download the latest drivers from Oracle driver download page.

classes12.zip for jdk 1.2/1.3
ojdbc14.jar for jdk 1.4

Add the jar to your classpath.
seema prakash
Ranch Hand

Joined: Nov 17, 2004
Posts: 59
Thanks for guiding me. Yes, I do have the driver installed When I installed oracle9i database, Personal Edition.I do have the jdbc/lib directory which has all the different jars. I ahve included the classes12.jar and the ojdbc14.jar in my classpath too.
seema prakash
Ranch Hand

Joined: Nov 17, 2004
Posts: 59
Thanks for the help. I got it working. I had problem with the driver connection. Now it works with the following lines:
DriverManager.registerDriver((Driver)Class.forName("oracle.jdbc.driver.OracleDriver").newInstance());
conn = DriverManager.getConnection("jdbc racle:thin:@DCXHEILER:1521 rcl","SYSTEM","password");//making the connection.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.lang.ClassCastException error