Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Oracle BLOB Insert using createTemporary
Hi,
I need to insert BLOB data into database creating temporary BLOB using createTemporary. I found this piece of code for writing to clob
import java.sql.*; import java.util.*; import java.text.*; /* -------------------------------------------------------------------
public static void main (String args []) throws SQLException {
try {
DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
Connection conn = DriverManager.getConnection ("jdbc:oracle:thin:@server:1521:sid", "uid", "pwd");
PreparedStatement ps = conn.prepareStatement("INSERT INTO CLOBTABLE VALUES (?)");
oracle.sql.CLOB newClob =
newClob.putString(1,"This string, up to 4 gigabytes will be inserted into the CLOB"); ps.setClob(1, newClob); int rowcnt = ps.executeUpdate(); System.out.println("Successful update of "+rowcnt+" row"); ps.close(); conn.close(); } catch (Exception e) { System.out.println("Java Exception caught, error message="+e.getMessage()); }
But when i try the following for BLOB it throws exception the
exception
"Java Exception caught, error message=ORA-22275: invalid LOB locator
specified"
PreparedStatement ps = conn.prepareStatement("INSERT INTO BLOBTABLE VALUES (?)");
oracle.sql.BLOB newBlob =
String str = "This string, up to 4 gigabytes will be inserted into the BLOB"; newBlob.setBytes(str.getBytes()); ps.setBlob(1, newBlob); int rowcnt = ps.executeUpdate(); -----------------
I am using oracle 9.2 and java 1.4 and ojdbc14.jar
I would really appreciate any help.
Thanks.
Malkit Received on Tue Nov 30 2004 - 20:40:37 CST