473,587 Members | 2,487 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to Update Blob with JDBC?

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

Connection conn = ds.getConnectio n();
conn.setAutoCom mit(false);
// insert a file
FileInputStream fis = new FileInputStream (fileName);
PreparedStateme nt call =
conn.prepareSta tement(
"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.executeUpd ate();
conn.commit();
call.close();
conn = ds.getConnectio n();
conn.setAutoCom mit(false);
Statement stm = conn.createStat ement();
ResultSet rs = stm.executeQuer y(
"select content from Input_File where file_id = 1 for
update");
rs.next();
Blob bb = rs.getBlob("con tent");
OutputStream os = bb.setBinaryStr eam(0);
int dataByte = 0;
while ((dataByte = fis.read()) != -1) {
os.write(dataBy te);
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 5179

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

Similar topics

0
3418
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 how to get the modified BLOB object back to Java after the PLSQL block has finished executing. I do: BLOB bl =...
7
11453
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 convert to Hex or something. I've tried a few things but can't quite get it. Here is simplified code. mysql_select_db($dbname, $connection);
1
6518
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 servlet:xxxxx.jsp initiateDownloadFri Jan 07 15:48:39 CST 2005com.ibm.db2.jcc.a.SqlException: 1 (in debug mode exception called at rs =
7
2332
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 8.2 FP9): db2 connect to sample db2 call sqlj.DB2_UPDATEJARINFO ('JMARC.JMB','JMB','file:JMB.sqlj')
4
8945
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: java.lang.AbstractMethodError: COM.ibm.db2.jdbc.net.DB2ResultSet.getBlob(I)Ljava/sql/Blob; What is the problem? How can i retrieve blob using this...
9
11072
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: SELECT UsrNbr, UsrPwd, UsrPwdChgD, UsrEmail, UsrChgUsrI, UsrChgDte FROM USERS WHERE UsrNbr = ? FETCH FIRST 1 ROWS ONLY FOR UPDATE This runs fine...
8
3851
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 zip file): 1)
1
16218
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. The table has 2 INTs and 1 BLOB column. So, I've scoured various docs and such, and the closest I've come up with is some sort of animal that...
2
7693
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).. For ths i ve used getBlob() specified in the ResultSet API docs. Bt when i run i get an error as com.mysql.jdbc.Blob@152c4d9 The above gets...
0
7920
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8215
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8347
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7973
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8220
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6626
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5394
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1454
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.