If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Problem in writing file to db2 database

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-21-05, 08:17
shan101983 shan101983 is offline
Registered User
 
Join Date: Oct 2005
Posts: 1
Problem in writing file to db2 database

Hai

I created the table to insert a clob data as follows
db2 => create table ctest(datas clob(65536))
DB20000I The SQL command completed successfully.
db2 => describe table ctest

Column Type Type
name schema name Length Scale Nulls

------------------------------ --------- ------------------ -------- ----- -----
-
DATAS SYSIBM CLOB 65536 0 Yes


1 record(s) selected.

////////////////////////////////////////////

I tried the following java code to insert a clob data.

public static synchronized Connection getConnection() throws Exception {

Connection m_connectionDatabase = null;
try {
Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");

// Get the connection to the database.
m_connectionDatabase = DriverManager.getConnection(
"jdbc b2:aps","","");
}catch (Exception e) {
throw new Exception("Failed to connect to the database. ", e);
}

return m_connectionDatabase;
}

public static void main(String a[]) {

File file = new File("d:\\a.txt");
InputStream fis = new FileInputStream(file);
Connection con = getConnection();
PreparedStatement pstmt = con.prepareStatement("insert into ctest values(?)");

//try 1
pstmt.setAsciiStream(1,fis,(int)file.length());

// try 2
pstmt.setCharacterStream(1,fis,(int)(file.length() ));

// try 3
pstmt.setBinaryStream(1,fis,(int)(file.length()));

// try 4
byte[] b = new byte[fis.available()];
fis.read(b);
pstmt.setBytes(1, b);


pstmt.executeUpdate();
pstmt.close();
fis.close();
}

///////////////
Result:
////////////////

If the file size is less than 32kb, it inserted successfully.

but if more than 32kb, it throws follwing exception
COM.ibm.db2.jdbc.DB2Exception: [IBM][CLI Driver][DB2/NT] SQL0352N An unsupported SQLTYPE was encountered in position "1" of the input list (SQLDA). SQLSTATE=56084

at COM.ibm.db2.jdbc.app.SQLExceptionGenerator.throw_S QLException(Unknown Source)
at COM.ibm.db2.jdbc.app.SQLExceptionGenerator.throw_S QLException(Unknown Source)
at COM.ibm.db2.jdbc.app.SQLExceptionGenerator.check_r eturn_code(Unknown Source)
at COM.ibm.db2.jdbc.app.DB2PreparedStatement.loadPara meters(Unknown Source)
at COM.ibm.db2.jdbc.app.DB2PreparedStatement.execute2 (Unknown Source)
at COM.ibm.db2.jdbc.app.DB2PreparedStatement.executeU pdate(Unknown Source)


//////////////////////
Can any body please help out to insert clob value.

Thanks in advance
V.Shan
Reply With Quote
  #2 (permalink)  
Old 10-22-05, 05:53
przytula przytula is offline
Registered User
 
Join Date: Nov 2004
Posts: 374
clob

have a look at previous post
http://www.dbforums.com/t1198711.html
__________________
Best Regards, Guy Przytula
DB2/ORA/SQL Services
DB2 DBA & Advanced DBA Certified
DB2 Dprop Certified
http://users.skynet.be/przytula/dbss.html
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On