Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2010
    Posts
    4

    Red face Unanswered: Getting the error DB2 SQL Error: SQLCODE=-302, SQLSTATE=22001, SQLERRMC=null

    Code:
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.InputStream;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    
    public class BlobUse
    {
    	Connection connection;
    	Statement statement;
    	ResultSet resultSet;
    	public void generateReport()
    	{
    		try
    		{
    			Class.forName("com.ibm.db2.jcc.DB2Driver").newInstance();
    		    String url = "jdbc:db2://localhost:50000/smartcit";
    		    Connection connection = DriverManager.getConnection(url, "db2admin", "password");
    		    PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO ADMINISTRATOR.BOOKCOVERS VALUES(?,?)"); 
    		  File imageFile = new File("c:\\redbookcover.jpg"); 
    		  InputStream inputStream = new FileInputStream(imageFile); 
    		  preparedStatement.setString(1," 0738425826"); 
    		  preparedStatement.setBinaryStream(2,inputStream,(int)(imageFile.length())); 
    		  preparedStatement.executeUpdate(); 
    			connection.close();
    		}
    
    		catch (FileNotFoundException e)
    		{
    		e.printStackTrace();
    		}
    
    		catch (ClassNotFoundException e)
    		{
    		e.printStackTrace();
    		}
    		catch (SQLException e)
    		{
    			System.out.println("SQL Exception");
    			System.out.println("=============");
    			System.out.println(e.getMessage()); // (1)
    			System.out.println("");
    		}catch (IllegalAccessException ex) {System.err.println(ex.getMessage());}
    	    catch (InstantiationException ex) {System.err.println(ex.getMessage());}
    		}
    		public static void main(String[] args)
    		{
    		new BlobUse().generateReport();
    		}
    	}
    I created the table using query: create table bookcovers (bookisbn varchar(10) not null, bookcover blob (1G)
    not null, primary key(bookisbn))

    This is the example program from IBM site to store an image on database from IBM site but I am unable to run it sucessfully. Please help

  2. #2
    Join Date
    Nov 2003
    Posts
    2,935
    Provided Answers: 12
    Code:
    c:\>db2 ? 22001
    
    SQLSTATE 22001: Character data, right truncation occurred; for example, an
    update or insert value is a string that is too long for the column, or a
    datetime value cannot be assigned to a host variable, because it is too small.
    Now count the number of characters in your setString() call and the number of characters allowed for bookisbn

  3. #3
    Join Date
    Jan 2010
    Posts
    4

    Thumbs up Problem solved. Thanks a lot shammat

    Thanks a lot shammat. . I love this forum

  4. #4
    Join Date
    Nov 2012
    Posts
    1

    Thanks!!!

    You made me remember that I had to change my Stored Prodecedure Definition.
    In my case I get the same message sending a callableStatement with a SP.

    CallableStatement stpCall = conx.prepareCall("{Call SMBDP.SPNAME(?,?,?,?)}");
    stpCall.setString(1, x);
    stpCall.setString(2, y);
    stpCall.setString(3, z);
    stpCall.registerOutParameter(4, Types.LONGVARCHAR);
    stpCall.executeUpdate();

    have to correspond to
    CREATE PROCEDURE FTSMR56A
    (
    IN x CHAR (00010) FOR SBCS DATA CCSID EBCDIC,
    IN y CHAR (00020) FOR SBCS DATA CCSID EBCDIC,
    IN z VARCHAR(00016) FOR SBCS DATA CCSID EBCDIC,
    OUT REGS VARCHAR(31500) FOR SBCS DATA CCSID EBCDIC
    )
    etc, etc.

    in my case.

Posting Permissions

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