Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I wrote a lot of parametrized queries where parameters are inserted by the user. If the user inserts strings longer than the field where parametrized value is referring to, DB2 throws a SQL0302N error.

There is a way to avoid it?

Example:
C#
Create Table Foo (Code Char(3) Not Null, Descr Varchar(50));

PreparedStatement ps = new PreparedStatement(
     "Select * From Foo Where Code = ? Or Descr = ?");
ps.setString(1, txtInput.value);
ps.setString(1, txtInput.value);

If the parametrized value is bigger than 3 characters then first parameter throws an exception.

What I have tried:

The use of «= TRIM(?)» or «Like ?» instead of «= ?» avoids the error.
But I'd like fix it modifyng the connection string. In this way I will be sure that error won't thrown any more, even if I forget to fix some queries.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900