• 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

BLOB Problem in DB2

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author & internet detective
Posts: 41878
909
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Why does your bag say "bombs"? The reason I ask is that my bag says "tiny ads" and it has stuff like this:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic