From: | "Jeroen Habets" <Jeroen(at)twofoldmedia(dot)com> |
---|---|
To: | <pgsql-jdbc(at)postgresql(dot)org> |
Subject: | Low Priority: Harmless but useless code in AbstractJdbc1Statement.setObject??? |
Date: | 2003-03-25 10:23:15 |
Message-ID: | LHEKIEALPFANFIKAIAPJGELDCLAA.Jeroen@twofoldmedia.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-jdbc |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi,
While looking at the PreparedStatement functionality of the
postgresql driver I ran in
AbstractJdbc1Statement.setObject(int parameterIndex, Object x))
into the following snippet of code.
if (x == null)
{
int l_sqlType;
if (x instanceof String)
l_sqlType = Types.VARCHAR;
else if (x instanceof BigDecimal)
l_sqlType = Types.DECIMAL;
else if (x instanceof Short)
l_sqlType = Types.SMALLINT;
else if (x instanceof Integer)
l_sqlType = Types.INTEGER;
else if (x instanceof Long)
l_sqlType = Types.BIGINT;
else if (x instanceof Float)
l_sqlType = Types.FLOAT;
else if (x instanceof Double)
l_sqlType = Types.DOUBLE;
else if (x instanceof byte[])
l_sqlType = Types.BINARY;
else if (x instanceof java.sql.Date)
l_sqlType = Types.DATE;
else if (x instanceof Time)
l_sqlType = Types.TIME;
else if (x instanceof Timestamp)
l_sqlType = Types.TIMESTAMP;
else if (x instanceof Boolean)
l_sqlType = Types.OTHER;
else
l_sqlType = Types.OTHER;
setNull(parameterIndex, l_sqlType);
return ;
}
According to my O'Reilly Java Language Reference, x instanceof
<Type>, where x == null will always return false...am I overlooking
something?
I tested it using the following class:
/**
* test class for 'x instanceof <Class>' where x is null
*/
public class InstanceOf {
public static void main(String[] args) {
Object x = null;
System.out.println("x instanceof Object: "+(x instanceof Object));
System.out.println("x instanceof String: "+(x instanceof String));
System.out.println("x instanceof Integer: "+(x instanceof
Integer));
}
}
With java version "1.4.1_01" I get:
$ java InstanceOf
x instanceof Object: false
x instanceof String: false
x instanceof Integer: false
-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 6.5.3 for non-commercial use <http://www.pgp.com>
iQA/AwUBPoAgA/IWL7P9qCbyEQKevQCgwTUiGCmM8h+Bqmz7OZRlj/rAEZ4AmwY3
fUmH1CLmMNXfmrChdFn/qtne
=Ndff
-----END PGP SIGNATURE-----
From | Date | Subject | |
---|---|---|---|
Next Message | Dave Cramer | 2003-03-25 10:43:12 | Re: Patch AbstractJdbc1Statement.setBoolean support BIT and |
Previous Message | Jeroen Habets | 2003-03-25 10:22:59 | Patch AbstractJdbc1Statement.setBoolean support BIT and INTEGER columns |