db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Ondruška <peter.ondruska+de...@kaibo.eu>
Subject Re: nulls in prepared statement
Date Wed, 20 Jul 2011 05:48:33 GMT
You must explicitly set value to null:

if (cobj.getPartNo()==null) pstmt.setNull(1, java.sql.Types.VARCHAR);
else pstmt.setString(1,cobj.getPartNo());

On Wed, Jul 20, 2011 at 4:42 AM, Tomcat Programmer
<tcprogrammer@yahoo.com> wrote:
> Hi Everyone,
> I've tried doing research on this on the web but can't seem to find a clear answer, I
hope someone can help.  I'm currently working on an application using Derby where the data
being entered is optional for a lot of the fields. The columns in the tables are defined using
VARCHAR data type and accept nulls.  If, in the code to do the insert or update,  someone
leaves a field empty in the application it will result in a null value being passed through
setString method like this:
> pstmt.setString(1,cobj.getPartNo());
> where the getPartNo() method returns null.  When this happens I get a null pointer exception.
 Is there a configuration parameter for Derby to accept Java nulls and treat them as SQL
nulls?   If not, the code is going to get incredibly ugly fast if each value has to be checked
for null and then issue a separate setNull() method call.
> Thanks in advance,
> TC

View raw message