SQLState with pg74.1jdbc3.jar

Поиск
Список
Период
Сортировка
От Moreno Mauri
Тема SQLState with pg74.1jdbc3.jar
Дата
Msg-id 4006A8AA.E3A2F43A@italtel.it
обсуждение исходный текст
Ответы Re: SQLState with pg74.1jdbc3.jar
Re: SQLState with pg74.1jdbc3.jar
Список pgsql-jdbc
Hi all,
I'm a newbie in JDBC code.

I tried to execute a Statement.executeUpdate() method to insert a row
already present in my Postgresql DB.

With JDBC I receive a SQLException but I would like to have
more informations about the error (something like Duplicate Key
Exception).

I read that SQLException class have the getSQLState() method, but
when I call it, the result is null (the getErrorCode() return always 0).

The same if I try to generate another error (an INSERT command
without specifying all NOT NULL colums of my table).

I use pg74.1jdbc3.jar on a i686 Intel - Suse host.

Here is the code (insertCommand is intentionally a wrong command)

public int execInsert(String insertCommand) {
        Statement stateSql;
        Connection conn;

        conn = <get the Connection>;

        try {
            stateSql = conn.createStatement();
            return(stateSql.executeUpdate(insertCommand));
        }
        catch (SQLException e) {
          System.out.println("SQLException: error code = " +
e.getErrorCode());
          System.out.println("SQLException: sqlstate   = " +
e.getSQLState());
         return(-1);
       }
}


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

Предыдущее
От: Kris Jurka
Дата:
Сообщение: Re: patch: improve exception propagation in testcases
Следующее
От: Paul Thomas
Дата:
Сообщение: Re: SQLState with pg74.1jdbc3.jar