473,383 Members | 1,717 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

How to Update Blob with JDBC?

Hi,
I am accessing DB2 8.2 (Windows) via JDBC type 4 and am having
troubles making Blob.setBinaryStream(long) work to update a BLOB
column.
Here is the excerpt of code that I am using:

Connection conn = ds.getConnection();
conn.setAutoCommit(false);
// insert a file
FileInputStream fis = new FileInputStream(fileName);
PreparedStatement call =
conn.prepareStatement(
"insert into input_file (file_id, file_name,
content) " +
"values (?, ?, ?)");
call.setInt(1, 1);
call.setString(2, fileName);
call.setBytes(3, new byte[1]);
call.executeUpdate();
conn.commit();
call.close();
conn = ds.getConnection();
conn.setAutoCommit(false);
Statement stm = conn.createStatement();
ResultSet rs = stm.executeQuery(
"select content from Input_File where file_id = 1 for
update");
rs.next();
Blob bb = rs.getBlob("content");
OutputStream os = bb.setBinaryStream(0);
int dataByte = 0;
while ((dataByte = fis.read()) != -1) {
os.write(dataByte);
bytesWritten++;
}
os.close();
conn.commit();
rs.close();
stm.close();

the following is DDL for input_file table:
CREATE TABLE INPUT_FILE (
FILE_ID INTEGER NOT NULL,
FILE_NAME VARCHAR(100),
CONTENT BLOB(104857600)
)

The result of running the above code is that the record inserted,
however the content of the blob is just one byte long and does not
contain the file I am trying to put in the blob (content column). It
seems that the work done by the second statement does not have any
effects on the column.
Can anybody help please!
Thanks
Nesa

Jun 20 '07 #1
0 5154

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Corrine | last post by:
I am trying to pass a temporary BLOB that I've created in Java, to a PLSQL function that modifies it, and then to retrieve this modified value back to Java, all using JDBC. I can't figure out...
7
by: sime | last post by:
Hi, I have a blob field in a mysql database table. I want to copy a blob from one record to another. I am having trouble transferring the data via a php variable. Maybe I need to addslashes or...
1
by: sid_mulpuru | last post by:
I am trying to read data from a DB2 Blob Data type Field (using wsad 5.1.0) using getBlob() which when executed gives an SQL Exception 2005-01-07 15:48:40,506 ERROR - Error in...
7
by: Jean-Marc Blaise | last post by:
Hi, The dev center calls sqlj.DB2_UPDATEJARINFO ('JMARC.JMB','JMB','file:JMB.sqlj') to update the sqlj routine source. I tried in CLP from the directory containing jar and sqlj files (Windows...
4
by: alan_sec | last post by:
Hi. I'm trying to retrieve blob obect from DB2 database using COM.ibm.db2.jdbc.net.DB2Driver driver. When i' m trying to get Blob from result set (resultSet.getBlob(1)) i got this exception:...
9
by: Acupuncture | last post by:
Hi, I am developing a JDBC application and I encountered this problem (DB2 for ISeries). I want to do a select for update and also use the fetch first rows clause. This is my sql statement: ...
8
by: Godzilla | last post by:
Dear all, I cannot find a solution for my problem with inserting a blob object (>4000 in length) into an ORACLE database via ODBC. I have tried the two ways of inserting the blob object (a...
1
by: shallowpool | last post by:
Can someone provide me the simple syntax necessary to insert or update to a row containing a single BLOB column, where the BLOB data will be obtained from a file? This is on a linux installation. ...
2
by: jith87 | last post by:
I m using JSP @ front end and MySql db @ back end and the connectivity thru JDBC. While retrieving a blob(MySql format) from the db back to JSP i need to convert ths to blob(Java comaptible format).....
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.