This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes JDBC and the fly likes Getting error while saving image as blob in oracle Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "Getting error while saving image as blob in oracle" Watch "Getting error while saving image as blob in oracle" New topic
Author

Getting error while saving image as blob in oracle

Deepa More
Ranch Hand

Joined: May 22, 2006
Posts: 68


Got following error at:
java.sql.SQLException: General error
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6987)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7115)
at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(JdbcOdbc.java:3111)
at sun.jdbc.odbc.JdbcOdbcStatement.execute(JdbcOdbcStatement.java:338)
at sun.jdbc.odbc.JdbcOdbcStatement.executeQuery(JdbcOdbcStatement.java:253)
at InsertFile.writeBLOBPut(InsertFile.java:87)
at InsertFile.main(InsertFile.java:35)
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1348
What kind of driver are you using?
Deepa More
Ranch Hand

Joined: May 22, 2006
Posts: 68
I am using Jdbc-Odbc driver:
Deepa More
Ranch Hand

Joined: May 22, 2006
Posts: 68
It works when I changed the driver to thin driver by
oracle.jdbc.driver.OracleDriver

Still I am confused as the method I used in example was BOLOB.putBytes(,,). And when I tried to use setBinaryStream of PreparedStatement it doesn't set the blob value in db. Code is:


There are so many ways of inserting blob data type, but what's the difference between them and when to use which method?


Thanks for support so far.
Deepa
[ January 30, 2007: Message edited by: Deepa More ]
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1348
You can google on: Blob setBinaryStream

and find example code like I paste here. After inserting empty_blob() then you select the blob for update (rather than using an update statement).

Google hit with blob code:

>> // execute this query to create a BLOB.
>> preparedStatement = connection.prepareStatement("INSERT INTO A (a1,
>> a2) VALUES ('a1', EMPTY_BLOB())");
>> preparedStatement .execute();
>>
>> // update it in place
>> preparedStatement = connection.prepareStatement("SELECT a2 FROM A
>> WHERE a1 = 'a1' FOR UPDATE");
>> resultSet = preparedStatement .executeQuery();
>> rs.next();
>> Blob blob = rs.getBlob(1);
>> OutputStream out = blob.setBinaryStream(1);

That is what I've used in the past and I was aiming for a solution that didn't require any Oracle-specific class casts.
Deepa More
Ranch Hand

Joined: May 22, 2006
Posts: 68
Thanks Carol for the reply.
I tried your solution, but
is giving me the exception saying that
java.sql.SQLException: Unsupported feature

Does this mean, this feature is supported in later versions of oracle.
Currently I am using Oracle9i.

Thanks again,
Deepa
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1348
What java version are you using?

java.sql.Blob's setBinaryStream documenation says it was added with JDK 1.4.

The oracle 9i driver shouldn't be a problem.
Deepa More
Ranch Hand

Joined: May 22, 2006
Posts: 68
Hi Carol,
I am using jdk142_08 and included classes12.jar from my Oracle9 home.
But still getting same SQLException of Unsupported feature.



Thanks
deepa
[ February 05, 2007: Message edited by: Deepa More ]
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1348
Originally posted by Deepa More:
Hi Carol,
I am using jdk142_08 and included classes12.jar from my Oracle9 home.
But still getting same SQLException of Unsupported feature.

[ February 05, 2007: Message edited by: Deepa More ]


Like I said, java.sql.Blob's setBinaryStream method was added with JDK 1.4. The 12 in classes12.zip is for jdk 1.2, so it's unlikely that jar supports that feature. A better bet would to use ojdbc14.jar, since it supports jdk 1.4.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Getting error while saving image as blob in oracle
 
Similar Threads
Retrieving image file from the database and displaying in the browser
How can I interact with OracleResultSet?
File download from Blob column does not work
how to safe send file?
two ResultSet for one connection