db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bryan Pendleton <bpendle...@amberpoint.com>
Subject Question about handling of string of length 0 in PreparedStatement.setString()
Date Tue, 23 Aug 2005 22:09:53 GMT
Hi, I'm wondering if someone has run into this and can
help me understand what's happening.

I'm porting some JDBC code from Another Database to Derby;
I'm using Derby on RedHat Linux.

My program contains a snippet of code something like:

   PreparedStatement stmt = conn.prepareStatement(
         "insert into my_table (a, b) values (?, ?)");
   stmt.setString(1, "1");
   stmt.setString(2, "");

Now, it so happens that the second column ('b', above)
is of type INTEGER, and nulls are allowed.

When I run this program in Another Database, what happens
is that the row is inserted, and the value of column 'b'
in the row is set to NULL.

When I run this program in Derby, what happens is that I
get an exception:

   org.apache.derby.client.am.SqlException: Invalid character
   string format for type INTEGER.

I tried poking around in the JDBC documentation to see what
it said about type conversions, but I got lost, so I thought
I'd ask the Derby list and see what people thought about
this particular behavior.

That is: is it valid for Derby to reject my insert? Or should
it have converted the value to NULL, like Another Database did?



View raw message