db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Matt Sanford <mzsanf...@aol.com>
Subject Re: Question about handling of string of length 0 in PreparedStatement.setString()
Date Tue, 23 Aug 2005 22:35:58 GMT
Hello,

    Not sure I can assist with more than my 2 cents. Since a blank 
string is different than the absence of value (null), I would argue that 
Derby is doing the correct thing, while the other DBMS is guessing at 
the user's intentions. The root cause of this specific message is that 
internally Derby is using Integer.valueOf which does not recognize "" as 
a valid number.

Thanks;
  -- Matt Sanford


bpendleton@amberpoint.com wrote:

> 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 10.1.1.0 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, "");
>   stmt.executeUpdate();
>
> 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?
>
> thanks,
>
> bryan
>
>

-- 
When the going gets tough, the weird turn pro.
  -- Hunter S. Thompson


Mime
View raw message