• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Getting error while saving image as blob in oracle

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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)
 
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What kind of driver are you using?
 
Deepa More
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using Jdbc-Odbc driver:
 
Deepa More
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Deepa what you did for resolving this problem, i am facing this problem now.
Please help to resolve or any other way to store image in DB

Deepa More wrote:

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)

 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic