update Blob field in ResultSet --URGENT

Hi,

Before install J2EE environnement, I manipulate Blob with jdbc interface:

I made a insert with the Blob field to null and after this insert I executed a "select for update" to get a updatable ResultSet and used updateBinaryStream() methode to set my file in the Blob. It works OK

Now, with J2EE environnement (Java 2 and Oracle 8 with Thin Oracle drivers 'classes12.zip')

I get a SQLException withe the same code source:

'ORA-01002: Extraction en rupture de squence '

(sorry I'm French...)

If I try to use the new Updatable ResultSet with a call:

Statement stat = aConn.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_UPDATABLE);

and try after to use the same methode 'setBinaryStream()' for update Blob field I have another Exception:

'ORA-01008: Toutes les variables ne sont pas li es '

if I use a simple 'select' or

'ORA-01002: Extraction en rupture de squence '

if I use a 'select for update'

(Sorry i'm always French...)

Someone could help me!!!!!

exemples:

1)

ls_Query = "select LC_PA_NOM from PA where ID_PA_NUMERO = 449 for update";

Statement stat = aConn.createStatement();

ResultSet rs= stat.executQuery(ls_Query );

if(rs.next())

{

rs.updateBinaryStream(1,theInputStream, theInputStream.available());

rs.updateRow();

}

=> raise SQLException: ORA 1002

2)

ls_Query = "select LC_PA_NOM from PA where ID_PA_NUMERO = 449 for update";

Statement stat = aConn.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_UPDATABLE);

ResultSet rs= stat.executQuery(ls_Query );

if(rs.next())

{

rs.updateBinaryStream(1,theInputStream, theInputStream.available());

rs.updateRow();

}

=> raise SQLException: ORA 1002

3)

ls_Query = "select LC_PA_NOM from PA where ID_PA_NUMERO = 449";

Statement stat = aConn.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_UPDATABLE);

ResultSet rs= stat.executQuery(ls_Query );

if(rs.next())

{

rs.updateBinaryStream(1,theInputStream, theInputStream.available());

rs.updateRow();

}

=> raise SQLException: ORA 1008

Thanks a lot

Felmerien

[2385 byte] By [felmerien] at [2007-9-26 2:43:56]
# 1

Here's an example of how we are getting binary objects in a database (in this case Oracle 8.1.7):

(This example is in moving a flat-file from the O/S to the database)

System.out.println("Step #1");

conn.setAutoCommit(false); // turn off auto-commit before opening the stream

sqlStmt = "select id, image from images where id = 38 for update";

ResultSet rs = stmt.executeQuery(sqlStmt);

if (!rs.next()) {

stmt.close();

disconnect();

return;

}

oracle.sql.BLOB blob = (oracle.sql.BLOB)((OracleResultSet)rs).getBlob(2);

System.out.println("Step #2");

File iFile = new File("test.jpg");

FileInputStream iStream = new FileInputStream(iFile);

OutputStream oStream = blob.getBinaryOutputStream();

System.out.println("Step #3");

int size = blob.getBufferSize();

byte[] buffer = new byte[size];

int length = -1;

System.out.println("Step #4");

while ((length = iStream.read(buffer)) != -1) {

oStream.write(buffer,0,length);

oStream.flush();

}

System.out.println("Step #5");

oStream.close();

iStream.close();

stmt.close();

System.out.println("Step #6");

conn.setAutoCommit(true); // turn auto-commit back on

sphicks at 2007-6-29 10:23:25 > top of Java-index,Archived Forums,Java Programming...