Reputation: 132
I use in a Java Application JDBC to query the DBMS. The application works correctly with Sql Server but I get this error in DB2 during one insert:
com.ibm.db2.jcc.am.SqlDataException: DB2 SQL Error: SQLCODE=-302, SQLSTATE=22001, SQLERRMC=1, DRIVER=3.63.75
The insert is made using the ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE
.
My query is a plain select of the table, then I declare my PreparedStatement
, passing the parameters and afterwards with the ResultSet
I do first the moveToInsertRow()
and then the insertRow()
.
Do you know if there are any problems with this approach using DB2?
As I told you before the same code works correctly with Sql Server.
Upvotes: 1
Views: 1885
Reputation: 1
Probably too late to add to this thread.. but someone else might find it useful
Got the same SQL Exception when trying to do a SELECT
: didn't realize the property value in WHERE
clause was exceeding the limit on the corresponding column
SELECT * FROM <schema>.<table_name> WHERE PropertyName = 'value';
value was a VARCHAR
type but exceeded the Length limit
Detailed exception does say it clearly that data integrity was violated: org.springframework.dao.DataIntegrityViolationException
So a good idea would be to do a length check on the value(s) that are being set on the properties before firing any queries to the database.
Upvotes: 0
Reputation: 6334
SQL Code -302 on DB2 means:
THE VALUE OF INPUT VARIABLE OR PARAMETER NUMBER position-number IS INVALID OR TOO LARGE FOR THE TARGET COLUMN OR THE TARGET VALUE
So it seems like you are trying to insert a value into a column which is too large or too short (e.g. Hello World
into a varchar(5)
). Probably the column has a different length in DB2 and sql-server or you are inserting different values.
Upvotes: 1