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 > Inserting Images in DB2

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-07-10, 08:58
jeganism jeganism is offline
Registered User
 
Join Date: Dec 2010
Posts: 3
Question Inserting Images in DB2

Hi All,

This is my first post and I am very new to DB2 .. So bare with the amateur posting etiquette and simplicity of the doubt.

My requirement:

To store Images in DB2 through JSPs.

Actions done:

Created table with a LOB column.
And I have also created the Auxiliary table and Index for the column.

Problem:

I have problem inserting image in the table. How do i mention the image in the insert query ?

Right now I am mentioning the whole path of the image and I am not successful in that.

Current query :

INSERT INTO CPAD.SIGNMASTER150MT (UNAME,SCODE,SIGNATURE)
VALUES (1111 ,'04','C:\Documents and Settings\cpad\Desktop\IMG_011255.jpg')


Any help|suggestion would be highly appreciable.

Thanks
Jegan
Reply With Quote
  #2 (permalink)  
Old 12-07-10, 10:39
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
There are plenty of examples in the manual, e.g. this: How to use LOB data type
Reply With Quote
  #3 (permalink)  
Old 12-08-10, 04:52
jeganism jeganism is offline
Registered User
 
Join Date: Dec 2010
Posts: 3
Thankzz

The above Insert query is drafted with the help of the manuals only.
But still I am getting the following error:

DB2 SQL error: SQLCODE: -408, SQLSTATE: 42821, SQLERRMC: SIGNATURE

Which says Insert not compatible with the column Signature (LOB column).

Can you give a real time example ? If possible ..


Thankzz in advance.
Jegan
Reply With Quote
  #4 (permalink)  
Old 12-22-10, 06:58
jeganism jeganism is offline
Registered User
 
Join Date: Dec 2010
Posts: 3
Question Status as of now on the same issue

Hi All,

This is the code as of now.

public static void main(String[] args) {

//PrintWriter pw = response.getWriter();
String connectionURL = "jdbc:db2://172.16.31.33:60000/DB2TLOC";
StringBuffer query=null;
Statement stmt= null;
PreparedStatement pst = null;
java.sql.Connection connection=null;
FileInputStream fis;
try
{
Class.forName("com.ibm.db2.jcc.DB2Driver").newInst ance();
connection = DriverManager.getConnection(connectionURL,"PWD", "PWD");
query=new StringBuffer("INSERT INTO CPAD.SIGNMASTER150MT (UNAME,SCODE,SIGNATURE) VALUES(?,?,?)");

stmt=connection.createStatement();
pst=connection.prepareStatement(query.toString());

File file = new File("C:/Documents and Settings/cpad/My Documents/RBILOGO.bmp");


pst.setString(1, "1252");
pst.setString(2, "1242");
pst.setBinaryStream(3, new FileInputStream(file),(int)file.length());

System.out.println("Image");

pst.executeUpdate();

System.out.println("Image has been inserted");

}
catch (Exception e)
{
System.out.println(e);
}

}


But still I am unable to store the image. The following is the error:

DB2 SQL error: SQLCODE: -301, SQLSTATE: 42895, SQLERRMC: 1


Any suggestions ??
Reply With Quote
  #5 (permalink)  
Old 12-22-10, 15:59
schintala schintala is offline
Registered User
 
Join Date: Apr 2005
Location: USA
Posts: 119
Did you look at the samples using LOBs in SQL? Check out them from below link. Look at DtLOB.Java file.

DB2 Universal Database
Reply With Quote
  #6 (permalink)  
Old 12-22-10, 17:34
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Quote:
Originally Posted by jeganism View Post

DB2 SQL error: SQLCODE: -301, SQLSTATE: 42895, SQLERRMC: 1

As usual, check the manual for SQLCODE -301. You have a data type mismatch in column 1.

By the way, I think it's a bad idea to call a column "UNAME" if it's numeric...
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