\0 and IllegalArgumentException

Поиск
Список
Период
Сортировка
От Sebastiaan van Erk
Тема \0 and IllegalArgumentException
Дата
Msg-id 1099043710.595.50.camel@localhost
обсуждение исходный текст
Ответы Re: \0 and IllegalArgumentException
Re: \0 and IllegalArgumentException
Список pgsql-jdbc
Hi,

I'm using postgres 7.4 with the latest JDBC driver, and had an insert
statement to insert data as follows

try
{
    ...
    ps.setCharacterStream(1, myStream, myStreamLength);
    ps.executeUpdate();
}
catch (SQLException e)
{
...
}

With this I was hoping to catch invalid inserts (with an SQLException),
however I'm getting:

java.lang.IllegalArgumentException: \0 not allowed

which is an UNCHECKED runtime exception, that in no way indicates
(programatically) that the insert failed.

I think very few people would expect a runtime exception on what
essentially amounts to a failed insert. Futhermore, it is very hard to
discover the SOURCE of the runtime exception (lots of things might throw
an IllegalArgumentException) and to programatically do something
sensible with this.

Thus in my opinion, an SQLException would be better here for at least
three reasons:
1) It's a checked exception (I'm counting on it happening)...
2) I will know where it came from (postgres)...
3) Now I'm totally unsure of what other kind of runtime exceptions the
postgres driver may throw for some reason or other, nor do I know how to
handle a runtime exception properly if one does occur... I want runtime
exceptions basically only on PROGRAMMATIC errors, errors that I as the
developer made and can fix. User data CAN in fact contain \0, and the
fact that postgres cannot handle this is an issue of the backend, which
(in the case of postgres, but certainly not in the case of all
databases) does not consider these kind of strings as valid. As the
developer (oblivious to what kind of backend database is used) I cannot
take any programmatic steps to avoid this problem (other than string
scanning caught IllegalArgumentExceptions for this specific problem).

In conclusion, I REALLY think that this is the wrong exception to be
thrown.

Greetings,
Sebastiaan van Erk



В списке pgsql-jdbc по дате отправления:

Предыдущее
От: Kris Jurka
Дата:
Сообщение: Re: Serializable transactions and SQLException
Следующее
От: Giampaolo Tomassoni
Дата:
Сообщение: Re: Serializable transactions and SQLException