• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Storing BLOB file in Database.

 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am getting an error while trying to insert a byte[] in blob field. Please let me know if I am doing somethng wrong. Here is the code.
Connection jdbcConn = null;
PreparedStatement sqlStatement = null;
//Statement stmt = null;
boolean autoCommit = true;
ResultSet sqlResults = null;
Blob imageBlob;
Blob pdfBlob;

try {

jdbcConn = XPDataSource.getConnection();
autoCommit = jdbcConn.getAutoCommit();
jdbcConn.setAutoCommit(false);
String insertSqlString =
"INSERT INTO XP_M_HOMEPAGE_CONTENT (SKEY, TOPIC,TITLE,MESSAGE,LINK_TEXT, LINK_BLOB,IMAGE_NAME) VALUES ("
+ skey
+ ",'"
+ bean.getTopic()
+ "','"
+ bean.getTitle()
+ "','"
+ bean.getMessage()
+ "','"
+ bean.getLinkText()
+ "', ?,'"
+ bean.getImageName()
+ "')";
Log.debug("", insertSqlString);
//stmt = jdbcConn.createStatement ();
sqlStatement = jdbcConn.prepareStatement(insertSqlString);

//InputStream imgInputStream = new BufferedInputStream(new FileInputStream(bean.getImageLink()));
InputStream pdfInputStream = new BufferedInputStream(new FileInputStream(bean.getPdfLink()));
//sqlStatement.setBinaryStream(1,imgInputStream,imgInputStream.available());
sqlStatement.setBinaryStream(1, pdfInputStream,pdfInputStream.available());

sqlStatement.executeUpdate();
//imgInputStream.close();
pdfInputStream.close();
jdbcConn.setAutoCommit(autoCommit);
jdbcConn.commit();
jdbcConn.close();
 
Ranch Hand
Posts: 775
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Aren't blobs one of the types where you first do an insert to create the server-side uninitialized object, followed by (before committing) a select to read back a client-side reference to work with?
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic