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 > Java on S/390 Problem

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-19-04, 08:50
tnssrini tnssrini is offline
Registered User
 
Join Date: Dec 2003
Posts: 9
Java on S/390 Problem

Hi

We have created a table with a single column of datatype BLOB in S/390.
We are trying to insert a picture image into the table using the java code given below.

We are using

DB2 Ver 6 on S/390
JDK Ver 1.3.1 and
COM.ibm.db2os390.sqlj.jdbc.DB2SQLJDriver as Driver

When executing this code, we are getting the following error:

java.sql.SQLException: DB2JDBCSection Received Error in Method executeQLCODE==
> -301 SQLSTATE ==> 42895 Error Tokens ==> <<DB2 6.1 ANSI SQLJ-0/JDBC 1.0>> 002
at COM.ibm.db2os390.sqlj.jdbc.DB2SQLJJDBCSection.setE rror(DB2SQLJJDBCSec
tion.java:1106)
at COM.ibm.db2os390.sqlj.jdbc.DB2SQLJJDBCSection.exec ute(DB2SQLJJDBCSect
ion.java:656)
at COM.ibm.db2os390.sqlj.jdbc.DB2SQLJPreparedStatemen t.executeUpdate(DB2
SQLJPreparedStatement.java:353)
at WriteBlob.writePicture(WriteBlob.java:47)
at WriteBlob.main(WriteBlob.java:64)


JAVA CODE :

import java.lang.*;
import java.sql.*;
import java.io.*;

public class WriteBlob {
private static PreparedStatement ps;
public static Connection getConnect(String argvݨ)
{
Connection con = null;
String url="";
String dbname = "";
String user_id = "";
String pwd = "";
try
{
Class.forName("COM.ibm.db2os390.sqlj.jdbc.DB2SQLJD river");
String URLprefix = "jdbc:db2os390sqlj:";
con = DriverManager.getConnection(URLprefix);
} // end try block
catch (Exception e){
e.printStackTrace();
} // end catch block
return con;
} // end of getConnect()


public static void writePicture(Connection con, String argvݨ){

//Assuming that the first column of the table is of BLOB data type
String insert_picture = "insert into BlobTbl (filename, blobcol) VALUES(?,?)";
try{
FileInputStream fis=new FileInputStream("ABC.JPG");
File sourcefile = new File("ABC.JPG");
long fileLength = sourcefile.length();
byteݨ fileContentByte = new byteÝ(int) fileLength¨;
fis.read(fileContentByte);
/**** sowmya **********/
//Initialising PreparedStatement ps with query
ps =con.prepareStatement(insert_picture);

//Using ps.setBinaryStream() instead of ps.setBytes to retrieve sourc
//ps.setBinaryStream(1,fis,fis.available());
ps.setString(1, "ABC.JPG");
ps.setBytes(2, fileContentByte);

//Execute the prepared statement
ps.executeUpdate();

}//end of try

catch(Exception ee){
ee.printStackTrace();
}//end of catch

}//end of writePicture()

public static void main(Stringݨ argv){

try{
//Establish connection
Connection conn = getConnect(argv);

//invoke writePicture method and pass connection object and command line input for tablename and columnname values
writePicture(conn,argv);

// Close connection object
conn.close();

} //end try block

catch (Exception ex)
{
ex.printStackTrace();
} //end catch block

}//end of main()

}//end of WriteBlob class


Please help us regarding the above...
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