Menu

#1391 setObject with UUID throws excepton

current-release
closed-works-for-me
None
1
2015-06-30
2015-04-22
No

We work with UUIDs. Every time when I call statement.setObject(parameterIndex, java.util.UUID.randumUUID().toString()); it throws an SQL exception. The column is generated with VarChar(100). Though there should be no Error. I solved it like this:
I modified in method setObject of org hsqldb.jdbc at line 1055:

public synchronized void setObject(int parameterIndex, Object x) throws SQLException
{
....if(UUID.randomUUID().getClass().equals(x.getClass()))
........x = x.toString();
....setParameter(parameterIndex, x);
}

It would be nice if Objects would be converted (when possible) to the Type of table. This may could be manged by an boolean.

Discussion

  • Fred Toussi

    Fred Toussi - 2015-04-22

    It does not look like a correct report. If you call:

        statement.setObject(parameterIndex, java.util.UUID.randumUUID().toString());
    

    you are calling the equivalent of this:

        String value = java.util.UUID.randumUUID().toString();
    
        statement.setObject(parameterIndex, value);
    

    The type of value is String, not UUID. Perhaps you are actually calling with a UUID object:

        statement.setObject(parameterIndex, java.util.UUID.randumUUID());
    

    In this case an exception is thrown as you may be using an Object that does not have a proper toString() method.

     
  • Daniel Brenzel

    Daniel Brenzel - 2015-04-22

    Sorry I have copied my first fix in the first line. java.util.UUID.randomUUID throws this exception although it has a toString-method. So I could fixed it with the toString method. I'm very sorry about that mistake.

     
  • Fred Toussi

    Fred Toussi - 2015-04-22

    HSQLDB cannot figure out if an Object has a proper toString() method that represents it fully (for example the java.sql.Date type) or the toString() method of the Object is used. It therefore plays it safe and rejects the call.

     
  • Fred Toussi

    Fred Toussi - 2015-06-30
    • status: open-works-for-me --> closed-works-for-me
    • assigned_to: Fred Toussi
    • Priority: 5 --> 1
     

Log in to post a comment.