Thread: SQLState with pg74.1jdbc3.jar
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); } }
On 15/01/2004 14:50 Moreno Mauri wrote: > 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). What version of PostgreSQL are you running? To get the error codes requires a 7.4 server. HTH -- Paul Thomas +------------------------------+---------------------------------------------+ | Thomas Micro Systems Limited | Software Solutions for the Smaller Business | | Computer Consultants | http://www.thomas-micro-systems-ltd.co.uk | +------------------------------+---------------------------------------------+
Hi!! I have an example code of pg73jdbc2.jar, maybe this help you. I have a question: How set the pg73jdbc2.jar files for work with jsp?? (SuSE 8.1) Dennis -----Original Message----- From: pgsql-jdbc-owner@postgresql.org [mailto:pgsql-jdbc-owner@postgresql.org] On Behalf Of Moreno Mauri Sent: Jueves, 15 de Enero de 2004 9:50 To: pgsql-jdbc@postgresql.org Subject: [JDBC] SQLState with pg74.1jdbc3.jar 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); } } ---------------------------(end of broadcast)--------------------------- TIP 8: explain analyze is your friend