Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 2010
    Posts
    3

    Question Unanswered: 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

  2. #2
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    There are plenty of examples in the manual, e.g. this: How to use LOB data type

  3. #3
    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

  4. #4
    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 ??

  5. #5
    Join Date
    Apr 2005
    Location
    USA
    Posts
    130
    Did you look at the samples using LOBs in SQL? Check out them from below link. Look at DtLOB.Java file.

    DB2 Universal Database

  6. #6
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    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...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •