473,602 Members | 2,792 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Error Reading DB2 BLOB field : Please Help

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
[com.mayco.jv.re sourcelibrary.M JVControllerSer vlet]
ERROR - Error in servlet:xxxxx.j sp initiateDownloa dFri Jan 07 15:48:39
CST 2005com.ibm.db2 .jcc.a.SqlExcep tion: 1

(in debug mode exception called at rs =
stmt.executeQue ry(query.toStri ng()) line from code)

To use getBlob() i need to have DB2 JDBC 2.0 driver and i have verified
the jdbc version which
when i print out on the system output shows up as this:

JDBC driver version is 1.3.70
JDBC Database Name is DB2/NT
JDBC Driver Name is IBM DB2 JDBC Universal Driver Architecture

I checked the class path in WSAD which points to db2jdbc.zip on the
local machine. So I am
not sure if JDBC 2.0 driver is being used or not.

Below is part of the code iam using. I would Greatly appreciate if you
could let
me know if this is a code problem or a driver issue and your thoughts
on what
needs to be done to get this working.

Thanks for your help and have a great weekend.


public void buildPDFBlob() throws Exception {

Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
String sSql = null;
StringBuffer query = new StringBuffer();
String fileName = "C:/P250.pdf";
ResultSetMetaDa ta rsmd;
try {

conn = getConnection(u serid, password, datasource);

stmt = conn.createStat ement();
DatabaseMetaDat a meta = conn.getMetaDat a();
query.append("s elect binaryblob,blob size FROM ");
query.append(co llection);
query.append(". FOLDERBLOBS ");
query.append("W HERE PAGEID = 4208");

rs = stmt.executeQue ry(query.toStri ng());

while (rs.next()) {

Blob blobObj = rs.getBlob("bin aryblob");

int MAX_FILE_SIZE = Integer.parseIn t(rs.getString( "blobsize") );

if (blobObj == null)
{
System.out.prin tln("Error creating Blob object - Blob object is null");
}
else
{

rsmd = rs.getMetaData( );

System.out.prin tln("Column's SQL type is :
"+rsmd.getColum nTypeName(1));
byte[] pdfData = new byte[MAX_FILE_SIZE];

InputStream is = blobObj.getBina ryStream();
is.read(pdfData );
FileOutputStrea m pdffile = new FileOutputStrea m(fileName);
pdffile.write(p dfData);

pdffile.close() ;

}

} // end if
} // end while
} // end try
catch (Exception e) {
throw e;

} finally {

try {

if (stmt != null) {
stmt.close();
}
} catch (Exception e) {
}
try {
if (conn != null) {
conn.close();
}
} catch (Exception e) {
}

}
}
Thanks

Sid

Nov 12 '05 #1
1 6518
I answer myself here. The code is fine basically the driver was not
supporting JDBC 2 API. So i had to upgrade it. I tried connection
pooling to get connection (JDBC 2.0 Optional API ) and websphere always
gets the old driver which did not support JDBC 2.0 API ( even though
the sqllib/usejdbc2 shows that jdbc 2 is use) .

So i had to use JDBC 2.0 core API to obtain connection and it pulled
the correct driver and everything was working fine. Any ideas why the
connection pooling didnt work ?

Thanks
Sid

sid_mulpuru wrote:
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
[com.mayco.jv.re sourcelibrary.M JVControllerSer vlet]
ERROR - Error in servlet:xxxxx.j sp initiateDownloa dFri Jan 07 15:48:39 CST 2005com.ibm.db2 .jcc.a.SqlExcep tion: 1

(in debug mode exception called at rs =
stmt.executeQue ry(query.toStri ng()) line from code)

To use getBlob() i need to have DB2 JDBC 2.0 driver and i have verified the jdbc version which
when i print out on the system output shows up as this:

JDBC driver version is 1.3.70
JDBC Database Name is DB2/NT
JDBC Driver Name is IBM DB2 JDBC Universal Driver Architecture

I checked the class path in WSAD which points to db2jdbc.zip on the
local machine. So I am
not sure if JDBC 2.0 driver is being used or not.

Below is part of the code iam using. I would Greatly appreciate if you could let
me know if this is a code problem or a driver issue and your thoughts
on what
needs to be done to get this working.

Thanks for your help and have a great weekend.


public void buildPDFBlob() throws Exception {

Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
String sSql = null;
StringBuffer query = new StringBuffer();
String fileName = "C:/P250.pdf";
ResultSetMetaDa ta rsmd;
try {

conn = getConnection(u serid, password, datasource);

stmt = conn.createStat ement();
DatabaseMetaDat a meta = conn.getMetaDat a();
query.append("s elect binaryblob,blob size FROM ");
query.append(co llection);
query.append(". FOLDERBLOBS ");
query.append("W HERE PAGEID = 4208");

rs = stmt.executeQue ry(query.toStri ng());

while (rs.next()) {

Blob blobObj = rs.getBlob("bin aryblob");

int MAX_FILE_SIZE = Integer.parseIn t(rs.getString( "blobsize") );

if (blobObj == null)
{
System.out.prin tln("Error creating Blob object - Blob object is null"); }
else
{

rsmd = rs.getMetaData( );

System.out.prin tln("Column's SQL type is :
"+rsmd.getColum nTypeName(1));
byte[] pdfData = new byte[MAX_FILE_SIZE];

InputStream is = blobObj.getBina ryStream();
is.read(pdfData );
FileOutputStrea m pdffile = new FileOutputStrea m(fileName);
pdffile.write(p dfData);

pdffile.close() ;

}

} // end if
} // end while
} // end try
catch (Exception e) {
throw e;

} finally {

try {

if (stmt != null) {
stmt.close();
}
} catch (Exception e) {
}
try {
if (conn != null) {
conn.close();
}
} catch (Exception e) {
}

}
}
Thanks

Sid


Nov 12 '05 #2

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

Similar topics

1
5021
by: Wayno | last post by:
My php logs are coming up empty. I have done all I can think of, and all that made sense to me. Can someone take a look at my php.ini please and tell me what you think may be the problem. I double-checked the path to my error log. It is in /var/www/logs/php_error_log Thanks. :) -Wayne Stevenson
7
7083
by: John | last post by:
I have over 5000 thumbnail pictures of size 5kb each. I would like to able to load all 5000 pictures and view 50 per page using mysql_data_seek(). I would like to know what are the advantages and disadvantages of using a MySQL blob field rather than reading the images directly from the file? How does one insert an image into a blob field? Can it be done dynamically? Thank you John
6
2230
by: Pierre-Benoit | last post by:
Hi there, I've a strange problem with ado.net and an Access db. I need to create a little C# app that take the content of "ole object" field and then save it into a file. The problem is that when I do the following Byte byteBLOBData = new Byte; byteBLOBData = (Byte)(ds.Tables.Rows);
1
3299
by: Roberto Castro | last post by:
I have some problems with the way I am showing the BLOB fields in the Image web controls. It does work on my localhost though sometimes I need to hit Refresh for the images to load properly. However, when I try to access the same page from another machine or when I test the code on a remote server the images just wouldn't show. The page I am talking about has 3 Image web controls. In the CodeBehind I am loading these controls by using an...
11
23006
by: Chris Fink | last post by:
I have setup an Oracle table which contains a blob field. How do I insert data into this field using C# and ADO.net?
1
2093
by: Ken | last post by:
Hello, I'm trying to read a Blob from Oracle and then write it to an audio file(.AU). I'm using Visual Studio.Net 2003 (VB). I can't seem to get my code to work. Will someone take a look at it and tell me what am I doing wrong. Any help would be appreciated. Thanks Dim Conn As OracleConnection = New OracleConnection("data source=XXXX;user id=XXXXX;password=XXXXX")
1
4804
by: yoes | last post by:
Dear all, I am very new in MySQL, I am working on image database project for my research and I have problem how to convert blob field into float in MySQL so that I can calculate the blob field with the MATH operation. Does any one how to do it ???? Thank you very much indeed , for your help.
0
2380
by: Big George | last post by:
Hello, I'm trying to save a jpg file of 300KB as a BLOB field in an Oracle 10g Database. If I try to call a Stored Procedure, it fails. If I use CommandText with SQL sentence, it success. I can't save the jpg file as a BLOB field using this Method (I'm calling a Stored Procedure): Private Sub save_BLOB(ByVal Photo As Byte())
1
3026
by: sang | last post by:
Hi i am doing my project in Mysql and PHP. My problem is i want to send a Blob field to my email using the Php. That is i am storing Candidates Resume in Blob field(Document format). I want to Choose the Particular Candidates Resume and the send to some Email address.But i want to know how can i get the field from mysql and how to send it to the particular emailid. Please any one help to solve my problem. Thanks and Regards Sang
0
7993
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7920
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8401
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8054
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8268
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5440
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3900
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2418
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1254
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.