DB2 SQL Error: SQLCODE=-302, SQLSTATE=22001, SQLERRMC=null

By | February 21, 2019

This error is the DB2 cryptic way of informing you that a value which an insert query tries to insert in a table is too large.

Usually when using java + hibernate we can define a member of an EJB as:


@Column(length = 10)
protected String receiver;

If somehow when the object is created we are allowed to set:

receiver="MyLongReceiverName";

when hibernate will try to persist the object into DB2 we will get:

DB2 SQL Error: SQLCODE=-302, SQLSTATE=22001, SQLERRMC=null

To avoid this issue make sure when defining columns with a restricted size to perform a size check before committing the object to the db.

In case an update to the column length is necessary, note that hibernate is not able to update the size of the column associated with the “receiver” member after changing the definition to:

@Column(length = 20)
protected String receiver;

The same issue will occur after a restart, hibernate will ignore the size change.

To properly update the table and avoid the error execute:

ALTER TABLE My_Table ALTER COLUMN receiver SET DATA TYPE VARCHAR(20);

Contribute to this site maintenance !

This is a self hosted site, on own hardware and Internet connection. The old, down to earth way 🙂. If you think that you found something useful here please contribute. Choose the form below (default 1 EUR) or donate using Bitcoin (default 0.0001 BTC) using the QR code. Thank you !

€1.00

2 thoughts on “DB2 SQL Error: SQLCODE=-302, SQLSTATE=22001, SQLERRMC=null

  1. Taraka Nagendra Kumar Busam

    I am getting similar error for select statement, what does that mean?

    Reply
    1. George Valentin Voina Post author

      It is the same issue. Depends on your select statement:
      – It may be that you in fact also insert some data in that select
      – or the select has a condition that somehow is linked with a column with that issue.
      – much more tricky can be the case you are not using UTF-8 encoding and you may have some string that is represented by DB2 on a bigger number of chars than you expect.

      Reply

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.