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 > Getting the error DB2 SQL Error: SQLCODE=-302, SQLSTATE=22001, SQLERRMC=null

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-24-10, 11:36
chetan1989 chetan1989 is offline
Registered User
 
Join Date: Jan 2010
Posts: 4
Red face 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
Reply With Quote
  #2 (permalink)  
Old 01-24-10, 11:53
shammat shammat is offline
Registered User
 
Join Date: Nov 2003
Posts: 2,407
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
Reply With Quote
  #3 (permalink)  
Old 01-24-10, 11:58
chetan1989 chetan1989 is offline
Registered User
 
Join Date: Jan 2010
Posts: 4
Thumbs up Problem solved. Thanks a lot shammat

Thanks a lot shammat. . I love this forum
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