Link to home
Start Free TrialLog in
Avatar of mariec
mariecFlag for Canada

asked on

writing Oracle 9 BLOB (JDBC)

Hello all!

I'm having trouble with Oracle Blobs through java. I don't know in which forum I should ask this question, but here goes:

I have an Oracle 9i database and JDBC 9.2 driver version.
I am using java v1.4.

I'm connecting to my database using the following:

DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
        _connection = DriverManager.getConnection("jdbc:oracle:thin:@host:port:ut", user, passwd);


In my code, i'm trying to write a blob to my table and the code looks like this:

import java.sql.*;
import oracle.sql.BLOB;

...

String sql = "SELECT VALIDITY FROM RANGEEVENT WHERE IDEVENT="+idLREvent;
stmt = Database.getConnection().createStatement();
ResultSet rs = stmt.executeQuery(sql);
if (rs.next()) {
        Blob myblob = rs.getBlob(1);
        OutputStream os = ((BLOB)myblob).setBinaryStream(0);
        os.write(validity);
        os.close();
}


BUT i get this error:
java.sql.SQLException: Unsupported function


After debugging, I found that it is "((BLOB)myblob).setBinaryStream(0);" which is causing this problem.

I've been reading the Oracle JDBC doc and can't find what the problem could be. I tried using OCI driver for connection but then I get ORA-06401: NETCMN error...
Avatar of mariec
mariec
Flag of Canada image

ASKER

BTW i've just changed that line to:

OutputStream os = ((BLOB)myblob).getBinaryOutputStream();

and it still doesnt work
Avatar of musdu
musdu

Hi,

you should use DBMS_LOB package to write blob data to database.

regards.
ASKER CERTIFIED SOLUTION
Avatar of grim_toaster
grim_toaster

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of seazodiac
seazodiac
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mariec

ASKER

grim_toaster's hints helped out alot. Query for update helps as well as disabling autocommit.

Seazodiac, its an interesting article but since the JDBC 2.0 standard is available, the code must be changed a little. Thanks for the doc though.