Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ClassCastException when casting my resultset to OracleResultSet

 
Katie Doody
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am working on some code that creates an empty blob in the database and then selects it to write to it. I have successfully used the exact same code before in an application I have created.

I am adding it to a different application and I get the following error:
java.lang.ClassCastException: org.jboss.resource.adapter.jdbc.WrappedResultSet

I thought maybe it was not loading the oracle driver class but this seems to be working?

Here is the code it fails on:

conn = easDBUtil.getConnection();
conn.setAutoCommit(false);
pstmt = conn.prepareStatement(easDBConstants.UPDATE_DRAWING);
pstmt.setInt(1,pkey);
Right Here*** rs = (OracleResultSet) pstmt.executeQuery();
rs.next();

Thanks for your help.
 
steve souza
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jboss probably wraps the oracle ResultSet, so the cast fails. Based on the documenation it looks like you can get the underlying oracle resultset, however unless you need to use some oracle extension then I would avoid that.

http://docs.jboss.org/jbossas/javadoc/3.2.7/connector/org/jboss/resource/adapter/jdbc/WrappedResultSet.html#getUnderlyingResultSet()
 
Katie Doody
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, I am confused why my other apps that are running on jboss with the same code work and this one does not?
 
Katie Doody
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Based on your response, I tried the following:
conn = easDBUtil.getConnection();
conn.setAutoCommit(false);
pstmt = conn.prepareStatement(easDBConstants.UPDATE_DRAWING);
pstmt.setInt(1,pkey);
wrs = pstmt.executeQuery();
System.out.println("Wrapped ResultSet class:" + wrs.getClass().getName());
ResultSet urs =
((org.jboss.resource.adapter.jdbc.WrappedResultSet) wrs)
.getUnderlyingResultSet();
System.out.println("Underlying ResultSet class:" + urs.getClass().getName());
OracleResultSet rs = (OracleResultSet) urs;
System.out.println ("Oracle ResultSet class:" + rs.getClass().getName());
rs.next();



I get the following error:
java.lang.ClassCastException: oracle.jdbc.driver.OracleResultSetImpl


on this line:
wrs = pstmt.executeQuery();
 
steve souza
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is the data type of wrs? please post the full code...
 
Katie Doody
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much. I am past that line, I had it defined wrong from some prior attempts. Here is the code now:

public void updateDrawing(BufferedInputStream bis) throws SQLException, EASException{
EASDBUtil easDBUtil = new EASDBUtil(logger);
Connection con = null;
int BUFFER_SIZE = 1024*2;
byte[] buffer = new byte[BUFFER_SIZE];//byte buffer 1024
byte[] tempBuffer = new byte[BUFFER_SIZE];//byte buffer 1024
int bytesRead = 0;
PreparedStatement pstmt = null;
ResultSet rs = null;
boolean badRecord = false;
int counter=0;
int totalBytesRead = 0;
OutputStream outbb = null;
GZIPOutputStream out = null;
// OracleResultSet rs = null;
ResultSet wrs = null;
int pkey = 0;

try {
//insert the empty blob so the record can be updated
con = easDBUtil.getConnection();
pstmt = con.prepareStatement(EASDBConstants.UPDATE_DRAWING);
pstmt.setInt(1,pkey);
wrs = pstmt.executeQuery();
System.out.println("Wrapped ResultSet class:" + wrs.getClass().getName());
ResultSet urs =
((org.jboss.resource.adapter.jdbc.WrappedResultSet) wrs)
.getUnderlyingResultSet();
System.out.println("Underlying ResultSet class:" + urs.getClass().getName());
rs = (OracleResultSet) urs;
System.out.println("Oracle ResultSet class:" + rs.getClass().getName());
rs.next();
oracle.sql.BLOB blob=((oracle.jdbc.driver.OracleResultSet)rs).getBLOB(1);
outbb=blob.getBinaryOutputStream();
out = new GZIPOutputStream(outbb);

// Simple read/write loop.
while((bytesRead = bis.read(buffer)) != -1) {
counter=counter+1;
out.write(buffer, 0, bytesRead);
totalBytesRead = totalBytesRead + bytesRead;
out.flush();
}

}catch(EASException ce){
logger.error("Exception in updateDrawing", ce);
throw ce;
}catch(Exception e){
logger.error("Exception in updateDrawing", e);
throw new EASException("EAS_EXEC_001");
}finally{
easDBUtil.closeDBResources(con, pstmt, null, rs);
}

}


It fails on:
rs = (OracleResultSet) urs;


The log shows:
16:06:09,560 INFO [STDOUT] Wrapped ResultSet classrg.jboss.resource.adapter.jdbc.WrappedResultSet
16:06:11,107 INFO [STDOUT] Underlying ResultSet classracle.jdbc.driver.OracleResultSetImpl
16:07:52,002 INFO [STDOUT] 16:07:52,002 ERROR [EASAttachDrawingDAO] Exception in updateDrawing
java.lang.ClassCastException: oracle.jdbc.driver.OracleResultSetImpl
at com.mud.eas.dao.EASAttachDrawingDAO.updateDrawing(EASAttachDrawingDAO.java:141)
 
steve souza
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are casting your result set as an OracleResultSet to a variable that is a ResultSet and so you are getting a cast error. Also, you should break that method up into simpler more atomic methods. For example put them in your easDBUtil class. For example easDBUtil.getOracleResultSet(...)

ResultSet rs = null;
rs = (OracleResultSet) urs;
 
Katie Doody
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I added all the extra stuff because of the jdbc wrapper I was trying to get the underlying resultset. Here is my original code that I have copied from my other application and the code works on jboss on the other application.

public void updateDrawing(BufferedInputStream bis) throws SQLException, EASException{
EASDBUtil easDBUtil = new EASDBUtil(logger);
Connection con = null;
int BUFFER_SIZE = 1024*2;
byte[] buffer = new byte[BUFFER_SIZE];//byte buffer 1024
byte[] tempBuffer = new byte[BUFFER_SIZE];//byte buffer 1024
int bytesRead = 0;
PreparedStatement pstmt = null;
ResultSet rs = null;
boolean badRecord = false;
int counter=0;
int totalBytesRead = 0;
OutputStream outbb = null;
GZIPOutputStream out = null;
// OracleResultSet rs = null;
ResultSet wrs = null;
int pkey = 0;

try {
//insert the empty blob so the record can be updated
con = easDBUtil.getConnection();
pstmt = con.prepareStatement(EASDBConstants.UPDATE_DRAWING);
pstmt.setInt(1,pkey);
rs = pstmt.executeQuery();
rs.next();
oracle.sql.BLOB blob=((oracle.jdbc.driver.OracleResultSet)rs).getBLOB(1);
outbb=blob.getBinaryOutputStream();
out = new GZIPOutputStream(outbb);

// Simple read/write loop.
while((bytesRead = bis.read(buffer)) != -1) {
counter=counter+1;
out.write(buffer, 0, bytesRead);
totalBytesRead = totalBytesRead + bytesRead;
out.flush();
}

}catch(EASException ce){
logger.error("Exception in updateDrawing", ce);
throw ce;
}catch(Exception e){
logger.error("Exception in updateDrawing", e);
throw new EASException("EAS_EXEC_001");
}finally{
easDBUtil.closeDBResources(con, pstmt, null, rs);
}

}


It fails on this line:
oracle.sql.BLOB blob=((oracle.jdbc.driver.OracleResultSet)rs).getBLOB(1);


With this error:
09:03:12,765 INFO [STDOUT] 09:03:12,359 ERROR [EASAttachDrawingDAO] Exception in updateDrawing
java.lang.ClassCastException: org.jboss.resource.adapter.jdbc.WrappedResultSet


I have been stuck on this issue for a few days and I am very confused as to why it would be working differently from on app to another.

Thank you for your help.
 
Katie Doody
Ranch Hand
Posts: 90
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just in case anyone is as confused as me. This application, unlike the others, is a web application and is picking up jboss's implemenation of the resultSet org.jboss.resource.adapter.jdbc.WrappedResultSet rather than my datasource Implementation(Oracle's oracle.jdbc.driver.OracleResultSet).

I am not sure if there is a way for it to know to use the Oracle implementation? This could be a post for jboss?
 
Aks kr
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Katie Doody
Did you get any alternate solution ?? i am stuck with the same problem.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic