Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql Interfaces Jdbc > Re: Issue with ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 4 of 4 Topic 1908 of 2089
Post > Topic >>

Re: Issue with NULL varchars

by laurenz.albe@[EMAIL PROTECTED] ("Albe Laurenz") Mar 25, 2008 at 03:46 PM

antony baxter wrote:
> I'm relatively knew to PostgreSQL, but have a fair amount of
> experience with JDBC and Oracle/SQL Server.
>=20
> I'm running PostgreSQL 8.3.0 on Mac OSX 10.5.2, am using the 8.3-603
> JDBC drivers, and using Java 1.5.0_13.
>=20
> I'm a bit confused by the results of the following test case code:

That is surprising, because the behaviour is the same on Oracle.
I ran your program there.
Can't say about SQL Server.

[...]
>       // Retrieve that Locale's ID by its Data:
>       p =3D c.prepareStatement("SELECT COUNT(*) FROM testing WHERE
varian=
t =3D ?");
>       p.setNull(1, java.sql.Types.VARCHAR);    // or p.setString(1,
varia=
nt);
>       rs =3D p.executeQuery();
>       while (rs.next())
>       {
>         System.out.println("SELECT COUNT: count=3D" + rs.getInt(1));
>       }
>       rs.close();
[...]

> The output, when I run this, is
[...]
> SELECT COUNT: count=3D0
>=20
> which implies that the table is created, the row is inserted, the row
> is retrieved when selecting by its Id, but when we try and search for
> anything with a NULL varchar value, nothing is returned.
>=20
> I've also tried swapping the setNull statements with setString(n, null)
-=
 same result.
>=20
> What am I missing?!

The fact that "NULL =3D NULL" evaluates to NULL and not to TRUE.

You can run the statement from the command line, without JDBC, and you
will
get the same result.

Maybe you wanted to use:

SELECT COUNT(*) FROM testing WHERE variant IS NULL;

which would return a nonzero result.

Yours,
Laurenz Albe

--=20
Sent via pgsql-jdbc mailing list (pgsql-jdbc@[EMAIL PROTECTED]
)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc
 




 4 Posts in Topic:
Issue with NULL varchars
antony.baxter@[EMAIL PROT  2008-03-25 15:19:11 
Re: Issue with NULL varchars
craig@[EMAIL PROTECTED]   2008-03-25 19:00:40 
Re: Issue with NULL varchars
craig@[EMAIL PROTECTED]   2008-03-25 19:25:59 
Re: Issue with NULL varchars
laurenz.albe@[EMAIL PROTE  2008-03-25 15:46:10 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Nov 22 6:15:24 CST 2008.