Oracle BLOB with JDBC

From: <vsingh2000_at_my-deja.com>
Date: Mon, 17 Apr 2000 20:58:17 GMT
Message-ID: <8dftt1$htm$1_at_nnrp1.deja.com>



Hi everyone,

I have a Java program that is trying to to insert into a BLOB column in an Oracle8.1.6 database. I am using JDBC OCI drivers.

I have a byte array and I want to write the contents of that bytearray into the BLOB column of my Oracle database.

I have seen many examples in Oracle documentation that first retrieves an empty blob filed and then updates it using the getBinaryOutputStream.

Does anyone know of a way that allows to create a oracle.sql.BLOB object from its one of the two default constructors?

I will appreciate if somene could help me with this piece of code.

Thanks,

Vikas

/*******
Code starts here
********/

// Load the Oracle JDBC driver:

        Class.forName ("oracle.jdbc.driver.OracleDriver");

// Connect to the database:

        oracle.jdbc.driver.OracleConnection conn = (oracle.jdbc.driver.OracleConnection)

	   DriverManager.getConnection (DbURL , User, Password);
	conn.setAutoCommit (false);

	byte bytearray[];	// have my input data in this byte array


// Create a BLOB object using
oracle.sql.BLOB myblob = new oracle.sql.BLOB(conn, bytearray)
// OR

// Create a BLOB object using
oracle.sql.BLOB myblob = new oracle.sql.BLOB(conn) OraclePreparedStatement ps = (OraclePreparedStatement) conn.prepareStatement("INSERT INTO lob_table (rownumber,name,blob_col) values (?,?,?)"); ps.setInt(1,1); ps.setString(2,"NAME"); ps.setBLOB(3,myblob); ps.executeUpdate(); conn.commit(); ps.close();


ERROR Message

I get the following exception when I execute the code given above

java.sql.SQLException: ORA-24813: cannot send or receive an unsupported LOB

	at java.lang.Throwable.<init>(Compiled Code)
	at java.lang.Exception.<init>(Compiled Code)
	at java.sql.SQLException.<init>(Compiled Code)
	at oracle.jdbc.dbaccess.DBError.throwSqlException(Compiled Code)
	at oracle.jdbc.oci8.OCIDBAccess.check_error(Compiled Code)
	at oracle.jdbc.oci8.OCIDBAccess.executeFetch(Compiled Code)
	at oracle.jdbc.oci8.OCIDBAccess.parseExecuteFetch(Compiled Code)
	at oracle.jdbc.driver.OracleStatement.executeNonQuery(Compiled
Code)
	at oracle.jdbc.driver.OracleStatement.doExecuteOther(Compiled
Code)
	at
oracle.jdbc.driver.OracleStatement.doExecuteWithBatch(Compiled Code)
	at oracle.jdbc.driver.OracleStatement.doExecute(Compiled Code)
	at
oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(Compiled Code)
	at
oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(Compiled Code)
	at com.mgic.oracle.test.AddBlob.UsePreparedStatement(Compiled
Code)
	at com.mgic.oracle.test.AddBlob.main(Compiled Code)
java.sql.SQLException: ORA-24813: cannot send or receive an unsupported LOB Sent via Deja.com http://www.deja.com/
Before you buy. Received on Mon Apr 17 2000 - 22:58:17 CEST

Original text of this message