Re: JDBC exception when call updateNull within an updateable ResultSet

From: Kris Jurka <books(at)ejurka(dot)com>
To: Olaf Liepelt <olafl(at)comrad(dot)co(dot)nz>
Cc: <pgsql-jdbc(at)postgresql(dot)org>, <pgsql-patches(at)postgresql(dot)org>
Subject: Re: JDBC exception when call updateNull within an updateable ResultSet
Date: 2002-10-14 17:44:39
Message-ID: Pine.LNX.4.33.0210141335540.30061-200000@leary.csoft.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc pgsql-patches


The following patch allows an updateable result set to set values to null.
Since it is impossible to do hashtable.put(key, null), I have created a
special object to represent the null value. This is simpler than creating
a separate collection to represent the fields set to null and trying to
keep that in sync with the regular values.

Thanks for the report.

Kris Jurka

On Fri, 11 Oct 2002, Olaf Liepelt wrote:

>
> Hi Kris, I've fund another bug. When creating an updateable result set
> and call 'updateNull' a NullPointerException is thrown: Exception in
> thread "main" java.lang.NullPointerException
> at java.util.Hashtable.put(Hashtable.java:397)
> at org.postgresql.jdbc2.AbstractJdbc2ResultSet.updateNull(AbstractJdbc2ResultSet.java:989)
> at PGTest.main(PGTest.java:50)
>
> code:
>
> import java.sql.*;
>
> public class PGTest {
> public static void main(String args[])
> throws Exception
> {
> String sql = "create table t(a serial primary key, b int)";
> Class.forName("org.postgresql.Driver");
> Connection conn = DriverManager.getConnection("jdbc:postgresql://localhost:5432/test", "comrad", "");
> try
> {
> Statement stmt = conn.createStatement();
> stmt.executeUpdate(sql);
> sql = "INSERT INTO t (a, b) VALUES (3, 4)";
> stmt.executeUpdate(sql);
> stmt.close();
> } catch (SQLException sqle)
> {
> sqle.printStackTrace();
> }
>
> try
> {
> sql = "select * from t for update";
> Statement stmt = conn.createStatement();
> ResultSet rs = stmt.executeQuery(sql);
> rs.updateNull("b");
> conn.commit();
> } catch (SQLException sqle)
> {
> sqle.printStackTrace();
> }
>
> Statement stmt = conn.createStatement();
> stmt.executeUpdate("DROP TABLE t");
> stmt.executeUpdate("DROP sequence t_a_seq");
> stmt.close();
> conn.close();
> }
> }
>
> Thanks Olaf
> --
> =============================
> | Olaf Liepelt |
> | Sofware Innovations Ltd. |
> | mail: olafl(at)comrad(dot)co(dot)nz |
> =============================
>

Attachment Content-Type Size
updateablers.patch text/plain 5.1 KB

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Jan Wieck 2002-10-15 14:37:41 Re: Changing Column Order (Was Re: MySQL vs PostgreSQL.)
Previous Message Alvaro Herrera 2002-10-14 15:15:59 Re: Changing Column Order (Was Re: MySQL vs PostgreSQL.)

Browse pgsql-patches by date

  From Date Subject
Next Message Justin Clift 2002-10-14 19:07:46 Re: Anyone want to assist with the translation of the Advocacy
Previous Message Anuradha Ratnaweera 2002-10-14 06:05:30 Re: Peer to peer replication of Postgresql databases