• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Inserting BLOB

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hai All,
I wanna insert a BLOB in to oracle DB and my sample code is :
Connection conn = null;
ResultSet result = null;
int columns = 0;
PreparedStatement ps = null;
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
OutputStream out = null;
String sqlInsert = "INSERT INTO TEST Values (?,EMPTY_BLOB())";
String sqlLockRow = "SELECT GENLIST FROM TEST WHERE PROID = ? FOR UPDATE";
String sqlUpdateBlob = "UPDATE TEST SET GENLIST = ? WHERE PROID = ?";
try {
//conn = this.getConnection();
conn = getConn() ;
if (conn != null) {
conn.setAutoCommit(false);
ps = conn.prepareStatement(sqlInsert);
ps.clearParameters();
ps.setInt(1 , proid.intValue());
ps.executeUpdate();
//conn.commit();
System.out.println(" inserted .... ");
conn.commit();
conn.setAutoCommit(false);
//lock new row
ps = conn.prepareStatement(sqlLockRow);
ps.clearParameters();
ps.setInt(1, proid.intValue());
result = ps.executeQuery();
conn.commit();
conn.setAutoCommit(false);
result.next();
// get byte[] from Hashtable
ObjectOutputStream os = new ObjectOutputStream(byteStream);
os.writeObject(aUserData);
os.close();
byte[] hashBytes = byteStream.toByteArray();

//update blob
ps = conn.prepareStatement(sqlUpdateBlob);

oracle.sql.BLOB dbBlob = (oracle.sql.BLOB )result.getBlob(1);
out = ((oracle.sql.BLOB)dbBlob).getBinaryOutputStream();
out.write(hashBytes);
out.flush();
out.close();
ps.setBlob(1,dbBlob);
ps.setInt(2, proid.intValue());
ps.executeUpdate();
conn.commit();
System.out.println(" done ........");
}
}
catch (Exception ex) {
System.out.println(" exception from saveUserHash() : "+ex);
}
system hang when it execute
result = ps.executeQuery();
I don't understand why ? and if any body got any
working code how to insert CLOB or BLOB into oracle that would be grate ...
Looking forward,
Greetings
NPA.
 
Ranch Hand
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is how I do it...

Rene
[ June 09, 2003: Message edited by: Rene Larsen ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic