Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

BLOB Problem in DB2

 
Senthamizh
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am facing the following problem while inserting a record with BLOB. See the following Java Program.
public boolean METHOD_NAME()
{
boolean sucessFlag = false;
File fileObject = new File("FILE_NAME.XLS");
FileInputStream finObject = new FileInputStream(fileObject);
Connection con = DbUtil.getDBConnention();
StringBuffer sb = new StringBuffer();
sb.append("INSERT INTO TABLE_NAME(BLOB_COLUMN) VALUES(?)");
PreparedStement pstmt = con.prepareStement(sb.toString());
pstmt.setBinaryStream(1, finObject, fileObject.length());
boolean sucessFlag = pstmt.execute();
}
The above code is executing fine without having Exception. But, I am getting successFlag as false after executing the SQL. Can anyone help me.
I am using DB2 Universal JDBC 2 Driver.
Thanks
Senthamizh
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35266
383
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all, how did this compile? You have the variable "sucessFlag" defined twice.
However, the code is acting as expected. The javadoc for execute() says that it returns true if the query returns a resultset and false if the query returns an update count. You would have to call getUpdateCount() to get the real result.
It is easier to call executeUpdate() instead of execute(). It is also clearer as to your intent. executeUpdate() returns the number of rows updated.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch Senthamizh!
You'll find this forum a great place to seek help on JDBC, and there aren't many rules you'll have to worry about, but one is that proper names are required. Please take a look at the JavaRanch Naming Policy and change your display name to match it.
In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.
Thanks!
bear
Forum Bartender
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic