ClassCastException

76 views
Skip to first unread message

Mark Paulus

unread,
Mar 12, 2009, 3:29:54 PM3/12/09
to log4...@googlegroups.com
Hi,

We would like to convert over to log4jdbc
in our application, but there seems to be one
small hitch....

Running on Solaris 10, using Glassfish server,
connecting to an Oracle DB via ojdbc14.jar, using
an oci connector. I've tested this against
a 10g RAC, and a 9i standalone, and the same
result occurs.

It's happening when we are trying to insert a CLOB
object via an update clause

Here's a synopsis of the log up to the exception:
select MSG_TXT from Table where Key = xxx FOR UPDATE nowait
select MSG_TXT from Table where Key = xxx FOR UPDATE nowait {executed in 78 msec}
ResultSet.new ResultSet returned
12. PreparedStatement.executeQuery() returned net.sf.log4jdbc.ResultSetSpy@1169d
12. ResultSet.next() returned true

This is the statement that is throwing the exception:
CLOB clob = ((oracle.jdbc.OracleResultSet) rs).getCLOB(1);
which throws this:
Throwable: java.lang.ClassCastException: net.sf.log4jdbc.ResultSetSpy
.
.
.

Can you give me a pointer on where to look or what further
info I can provide, or what I need to do to debug this?

Thanks.

Here's the relevant java code:
st = con.prepareStatement(sbQry.toString());
rs = st.executeQuery();
if (rs.next()) {
CLOB clob = ((oracle.jdbc.OracleResultSet) rs).getCLOB(1);


Arthur Blake

unread,
Mar 12, 2009, 3:38:56 PM3/12/09
to log4jdbc
Yes, the problem is that log4jdbc wraps the ResultSet with it's own
proxy version of the ResultSet,
So the cast itself is throwing the exception.

If you are running the 1.2 alpha 2 you can change your code to the
following:

CLOB clob;
if (rs instanceof net.sf.log4jdbc.ResultSetSpy)
{
clob = ((oracle.jdbc.OracleResultSet)
((net.sf.log4jdbc.ResultSetSpy)rs).getRealResultSet()).getCLOB
(1);
}
else
{
clob = ((oracle.jdbc.OracleResultSet) rs).getCLOB(1);
}

(warning: I just type the code out above real quick and haven't
verified it- but it should give you the idea!)

If you do this all over your code, you might want to make some kind of
static utility method that does this.
It's not very portable code anyway (because it relies on an Oracle
custom method...)

Mark Paulus

unread,
Mar 12, 2009, 5:13:15 PM3/12/09
to log4...@googlegroups.com
That worked, just had to do one addtional cast:
CLOB clob;
if (rs instanceof net.sf.log4jdbc.ResultSetSpy) {
clob = (CLOB)(((net.sf.log4jdbc.ResultSetSpy)rs).getRealResultSet()).getClob(1);
} else {
clob = ((oracle.jdbc.OracleResultSet) rs).getCLOB(1);
}

There was one other issue. When I used your downloaded
jar file, I got the following exception:
Throwable: java.lang.Exception: java.lang.Exception:
java.lang.NoSuchMethodError:
net.sf.log4jdbc.ResultSetSpy.getRealResultSet()Ljava/sql/ResultSet;
at .........

I had downloaded the source, and when I added the source as an
additional project (I'm using Netbeans 6.5 as my Dev env),
and rebuilt and deployed to Glassfish, it all worked fine.

Arthur Blake

unread,
Mar 12, 2009, 5:29:42 PM3/12/09
to log4...@googlegroups.com
hmm, that's odd. Are you sure that you used the correct download?
(either http://log4jdbc.googlecode.com/files/log4jdbc3-1.2alpha2.jar or
http://log4jdbc.googlecode.com/files/log4jdbc4-1.2alpha2.jar)

I'm assuming you are using the JDBC 3 version (because if you are
using the JDBC 4 version
it would be far superior to use the Wrapper interface to accomplish this...)

Arthur Blake

unread,
Jun 17, 2009, 11:15:28 PM6/17/09
to log4...@googlegroups.com
Can you describe the error you are getting?

On Wed, Jun 17, 2009 at 9:05 PM, Eric<ethe...@gmail.com> wrote:
> Fix makes sense, but does not work for us as it is Spring that is
> making the call.  Any other ideas?
>
> -e

Reply all
Reply to author
Forward
0 new messages