db2jcc_license_cisuz.jar
db2jcc_license_cu.jar
com.ibm.db2.jcc.c.SqlException
at com.ibm.db2.jcc.c.ec.<init>(ec.java:183)
at com.ibm.db2.jcc.b.d.b(d.java:1328)
at com.ibm.db2.jcc.c.s.a(s.java:748)
at com.ibm.db2.jcc.c.s.U(s.java:1393)
at com.ibm.db2.jcc.c.wf.getClob(wf.java:914)
.
Setting up the environment for testing:
ZFZVF.T_LOB (
(24),
TXT CLOB(2M) LOGGED
COMPACT,
IMG BLOB(2M) LOGGED
COMPACT
);
ZFZVF.NJ_GT;
;
ZFZVF.NJ_GT (
ID
.
ZTBS
.
NJBS
.
ND
(4),
NJNR BLOB(2M) LOGGED
COMPACT,
SJC
);
;
COMMENT
ZFZVF.NJ_GT
;
COMMENT
ZFZVF.NJ_GT (
ID
.
ZTBS
.
NJBS
.
ND
.
NJNR
.
SJC
);
;
Examples are as follows:
lob;
java.io.*;
java.sql.*;
* DB2 Clob, Blob Bug exploration
* File:
.java
* User: leizhimin
* Date: 2008-3-3 8:56:00
* /
TestLob4DB2{
String url =
String username =
;
String password =
;
String driverClassName =
;
* Get database Connection
*
* @return Database Connection
* /
Connection makeConnection() {
Connection conn =
;
{
Class.forName(driverClassName);
}
(ClassNotFoundException e) {
e.printStackTrace();
}
{
conn = DriverManager.getConnection(url, username, password);
}
(SQLException e) {
e.printStackTrace();
}
conn;
}
* Test connection
* /
testConnection() {
Connection conn = makeConnection();
{
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(
);
(rs.next()) {
String s1 = rs.getString(1);
String s2 = rs.getString(2);
System.out.println(s1 + s2);
}
rs.close();
stmt.close();
}
(SQLException e) {
e.printStackTrace();
}
{
{
conn.close();
}
(SQLException e) {
e.printStackTrace();
}
}
}
* Insert file test
* /
testInsertlob() {
Connection conn = makeConnection();
{
conn.setAutoCommit(
);
File txtFile =
File(
);
File imgFile =
File(
);
txt_len = (
) txtFile.length();
img_len = (
) imgFile.length();
{
InputStream fis1 =
FileInputStream(txtFile);
InputStream fis2 =
FileInputStream(imgFile);
PreparedStatement pstmt = conn.prepareStatement(
);
pstmt.setAsciiStream(1, fis1, txt_len);
pstmt.setBinaryStream(2, fis2, img_len);
pstmt.executeUpdate();
conn.commit();
}
(FileNotFoundException e) {
e.printStackTrace();
}
}
(SQLException e) {
e.printStackTrace();
}
{
{
conn.close();
}
(SQLException e) {
e.printStackTrace();
}
}
}
* Querying DB2 Clob tests throws an exception
* /
testQueryLob() {
Connection conn = makeConnection();
{
conn.setAutoCommit(
);
PreparedStatement stmt = conn.prepareStatement(
);
ResultSet rs = stmt.executeQuery();
(rs.next()) {
Clob clob = rs.getClob(
);
Blob blob = rs.getBlob(
);
InputStreamReader ir = (InputStreamReader) clob.getCharacterStream();
File fileOutput =
File(
);
FileOutputStream fo =
FileOutputStream(fileOutput);
c;
((c = ir.read()) != -1) {
fo.write(c);
;
}
fo.close();
}
}
(SQLException e) {
e.printStackTrace();
}
(IOException e) {
e.printStackTrace();
}
{
{
conn.close();
}
(SQLException e) {
e.printStackTrace();
}
}
}
* Query DB2 Blob tests
* /
testBlobQuery() {
Connection conn = makeConnection();
{
conn.setAutoCommit(
);
PreparedStatement stmt = conn.prepareStatement(
);
ResultSet rs = stmt.executeQuery();
i = 0;
(rs.next()) {
Blob blob = rs.getBlob(1);
InputStream inputStream = blob.getBinaryStream();
File fileOutput =
File(
+ i +
);
FileOutputStream fo =
FileOutputStream(fileOutput);
c;
((c = inputStream.read()) != -1)
fo.write(c);
fo.close();
System.out.println(
+ i +
);
i++;
}
}
(SQLException e) {
}
(FileNotFoundException e) {
e.printStackTrace();
}
(IOException e) {
e.printStackTrace();
}
{
{
conn.close();
}
(SQLException e) {
e.printStackTrace();
}
}
}
* Querying DB2 Clob tests throws an exception
* /
testClobQuery() {
Connection conn = makeConnection();
{
conn.setAutoCommit(
);
PreparedStatement stmt = conn.prepareStatement(
);
ResultSet rs = stmt.executeQuery();
conn.commit();
(rs.next()) {
Clob clob = rs.getClob(1);
InputStream is = clob.getAsciiStream();
File fileOutput =
File(
);
FileOutputStream fo =
FileOutputStream(fileOutput);
c;
((c = is.read()) != -1)
fo.write(c);
fo.close();
;
}
}
(SQLException e) {
e.printStackTrace();
}
(FileNotFoundException e) {
e.printStackTrace();
}
(IOException e) {
e.printStackTrace();
}
{
{
conn.close();
}
(SQLException e) {
e.printStackTrace();
}
}
}
main(String args[]) {
testConnection();
testInsertlob();
testBlobQuery();
testClobQuery();
}
}