Re: JDBC exception when call updateNull within an updateable ResultSet - Mailing list pgsql-patches

From Kris Jurka
Subject Re: JDBC exception when call updateNull within an updateable ResultSet
Date
Msg-id Pine.LNX.4.33.0210141335540.30061-200000@leary.csoft.net
Whole thread Raw
List 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@comrad.co.nz  |
> =============================
>

pgsql-patches by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: [HACKERS] ALTER TABLE ... ADD COLUMN
Next
From: Peter Eisentraut
Date:
Subject: Re: translation