• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Storing BLOB file in Database.

 
sudhakar Tadepalli
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • 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();
 
Reid M. Pinchback
Ranch Hand
Posts: 775
  • Mark post as helpful
  • send pies
  • 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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic