By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,679 Members | 2,749 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,679 IT Pros & Developers. It's quick & easy.

Error Reading DB2 BLOB field : Please Help

P: n/a
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.resourcelibrary.MJVControllerServlet]
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 =
stmt.executeQuery(query.toString()) 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";
ResultSetMetaData rsmd;
try {

conn = getConnection(userid, password, datasource);

stmt = conn.createStatement();
DatabaseMetaData meta = conn.getMetaData();
query.append("select binaryblob,blobsize FROM ");
query.append(collection);
query.append(".FOLDERBLOBS ");
query.append("WHERE PAGEID = 4208");

rs = stmt.executeQuery(query.toString());

while (rs.next()) {

Blob blobObj = rs.getBlob("binaryblob");

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

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

rsmd = rs.getMetaData();

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

InputStream is = blobObj.getBinaryStream();
is.read(pdfData);
FileOutputStream pdffile = new FileOutputStream(fileName);
pdffile.write(pdfData);

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
Share this Question
Share on Google+
1 Reply


P: n/a
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.resourcelibrary.MJVControllerServlet]
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 =
stmt.executeQuery(query.toString()) 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";
ResultSetMetaData rsmd;
try {

conn = getConnection(userid, password, datasource);

stmt = conn.createStatement();
DatabaseMetaData meta = conn.getMetaData();
query.append("select binaryblob,blobsize FROM ");
query.append(collection);
query.append(".FOLDERBLOBS ");
query.append("WHERE PAGEID = 4208");

rs = stmt.executeQuery(query.toString());

while (rs.next()) {

Blob blobObj = rs.getBlob("binaryblob");

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

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

rsmd = rs.getMetaData();

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

InputStream is = blobObj.getBinaryStream();
is.read(pdfData);
FileOutputStream pdffile = new FileOutputStream(fileName);
pdffile.write(pdfData);

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 discussion thread is closed

Replies have been disabled for this discussion.