 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Nikhil Guest
|
Posted: Wed Apr 28, 2004 12:41 am Post subject: OracleThinBlob ClassCast Exception |
|
|
Hi,
We are using weblogic8.1 jdk1.4.2 And oracle 8i.
We are trying to set the value for Blob column using the following
code snippet :-
The error we are seeing on this line "java.io.OutputStream os =
((OracleThinBlob)blob).getBinaryOutputStream();
" is:-
java.lang.ClassCastException
at com.aetrion.lucene.store.DBDirectory.setBLOB
_________________________________________________________________________
private void closeStream(String name, DBOutputStream os)
{
Connection conn = null;
ResultSet rs = null;
try{
byte[] data = os.toByteArray();
System.out.println("Length of the data is" + data.length);
conn = DriverManager.getConnection(
db.url, db.username, db.password);
PreparedStatement ps = conn.prepareStatement(
"update " + tableName + " set name = ?, lastmodified = ?, length
= ?, data = empty_blob() where name = ? and directory_name = ?");
ps.setString(1, name);
ps.setString(2, String.valueOf(System.currentTimeMillis()));
ps.setLong(3, (long)data.length);
// ps.setBytes(4, data);
ps.setString(4, name);
ps.setString(5, directoryName);
int rowCount = ps.executeUpdate();
if(rowCount != 1){
error("No data saved");
}
conn.setAutoCommit(false);
String selectStmt = "select data from lucene_indeces where name
= ? and directory_name = ? for update";
PreparedStatement pstmt = conn.prepareStatement( selectStmt );
pstmt.setString( 1, name );
pstmt.setString( 2, directoryName );
rs = pstmt.executeQuery();
rs.next(); //if (!rs.next() ) ERRLR_CONDITION
setBLOB( rs, 1, data );
conn.setAutoCommit(true);
} catch(SQLException e){
error("SQL error saving data", e);
} catch(IOException e){
error("IO error saving data", e);
}
catch(Exception e){
error("error saving data", e);
}
finally {
close(conn);
}
}
public void setBLOB (ResultSet rs, int inIndex, byte [] inBytes)
throws Exception
{
//oracle.sql.BLOB blob = (oracle.sql.BLOB)rs .getObject( inIndex
);
//java.io.OutputStream os = blob.getBinaryOutputStream();
java.sql.Blob blob = rs.getBlob("DATA");
java.io.OutputStream os =
((OracleThinBlob)blob).getBinaryOutputStream();
os.write(inBytes);
os.flush();
os.close();
}
____________________________________________________________________________
|
|
| Back to top |
|
 |
Roedy Green Guest
|
Posted: Wed Apr 28, 2004 1:45 am Post subject: Re: OracleThinBlob ClassCast Exception |
|
|
On 27 Apr 2004 17:41:34 -0700, [email]g_nick_2000 (AT) yahoo (DOT) com[/email] (Nikhil) wrote or
quoted :
| Quote: | java.lang.ClassCastException
at com.aetrion.lucene.store.DBDirectory.setBLOB
|
see http://mindprod.com/jgloss/errormessages.html#CASTCLASSEXCEPTION
You have to tell us which line in your code that happened on.
In any case one of your casts was overly optimistic about what it was
being handed. You can display the class of the object you got as a
clue as to what went wrong. use .getClass().toString().
--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
|
|
| Back to top |
|
 |
Nikhil Guest
|
Posted: Wed Apr 28, 2004 2:19 pm Post subject: Re: OracleThinBlob ClassCast Exception |
|
|
Hi Roedey,
Thanks for sending the reply but we didnt get any clue till now. I
am mentioning the line number.
java.sql.Blob blob = rs.getBlob("DATA");
java.io.OutputStream os
=((OracleThinBlob)blob).getBinaryOutputStream();
Latter line is giving the problem.
Thanks.
Nikhil
[email]g_nick_2000 (AT) yahoo (DOT) com[/email] (Nikhil) wrote in message news:<cdf89255.0404271641.7c31c456 (AT) posting (DOT) google.com>...
| Quote: | Hi,
We are using weblogic8.1 jdk1.4.2 And oracle 8i.
We are trying to set the value for Blob column using the following
code snippet :-
The error we are seeing on this line "java.io.OutputStream os =
((OracleThinBlob)blob).getBinaryOutputStream();
" is:-
java.lang.ClassCastException
at com.aetrion.lucene.store.DBDirectory.setBLOB
_________________________________________________________________________
private void closeStream(String name, DBOutputStream os)
{
Connection conn = null;
ResultSet rs = null;
try{
byte[] data = os.toByteArray();
System.out.println("Length of the data is" + data.length);
conn = DriverManager.getConnection(
db.url, db.username, db.password);
PreparedStatement ps = conn.prepareStatement(
"update " + tableName + " set name = ?, lastmodified = ?, length
= ?, data = empty_blob() where name = ? and directory_name = ?");
ps.setString(1, name);
ps.setString(2, String.valueOf(System.currentTimeMillis()));
ps.setLong(3, (long)data.length);
// ps.setBytes(4, data);
ps.setString(4, name);
ps.setString(5, directoryName);
int rowCount = ps.executeUpdate();
if(rowCount != 1){
error("No data saved");
}
conn.setAutoCommit(false);
String selectStmt = "select data from lucene_indeces where name
= ? and directory_name = ? for update";
PreparedStatement pstmt = conn.prepareStatement( selectStmt );
pstmt.setString( 1, name );
pstmt.setString( 2, directoryName );
rs = pstmt.executeQuery();
rs.next(); //if (!rs.next() ) ERRLR_CONDITION
setBLOB( rs, 1, data );
conn.setAutoCommit(true);
} catch(SQLException e){
error("SQL error saving data", e);
} catch(IOException e){
error("IO error saving data", e);
}
catch(Exception e){
error("error saving data", e);
}
finally {
close(conn);
}
}
public void setBLOB (ResultSet rs, int inIndex, byte [] inBytes)
throws Exception
{
java.sql.Blob blob = rs.getBlob("DATA");
java.io.OutputStream os =
((OracleThinBlob)blob).getBinaryOutputStream();
os.write(inBytes);
os.flush();
os.close();
}
____________________________________________________________________________
|
|
|
| Back to top |
|
 |
Roedy Green Guest
|
Posted: Wed Apr 28, 2004 8:59 pm Post subject: Re: OracleThinBlob ClassCast Exception |
|
|
On 28 Apr 2004 07:19:36 -0700, [email]g_nick_2000 (AT) yahoo (DOT) com[/email] (Nikhil) wrote or
quoted :
| Quote: |
java.sql.Blob blob = rs.getBlob("DATA");
java.io.OutputStream os
=((OracleThinBlob)blob).getBinaryOutputStream();
|
So getBlob is NOT giving in an OraclethinBlob.
Just WHAT IS it giving you? Lets find out:
java.sql.Blob blob = rs.getBlob("DATA");
System.out.println("blob is really a " + blob.getClass().toString() );
--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|