[postgis-users] JDBC 1.0.0: How to setNull() in a PreparedStatement?

Jean-Pierre Quirion jpquirion at yahoo.ca
Wed Mar 2 10:42:27 PST 2005


Hi,

my configuration:
Postgres 8.0.0 Beta 4
PostGis 1.0.0RC3
JDBC: pg80b1.308.jdbc3.jar and the new postgis.jar for
Postgis 1.0.0 (2005/02/24)

I am using Prepared Statements for insert/update in
JDBC and I don't find a proper way how to insert a
NULL value in the geom column.

I cannot switch to another PreparedStatement if there
is no geom value. I successfully entered an empty
geometry but that is not a solution. 

Example:
INSERT INTO station (id, geom) VALUES (?, ?)
st.setInt(1, id); // works of course
st.setObject(2, Types.JAVA_OBJECT);
throws
--> org.postgresql.util.PSQLException: Unknown Types
value.

st.setNull(2, Types.OTHER);
throws
--> org.postgresql.util.PSQLException:
setNull(i,Types.OTHER) is not supported; use
setObject(i,nullobject,Types.OTHER) instead.

st.setObject(2, (PGobject) null, Types.OTHER); 
// or
st.setObject(2, (PGgeometry) null, Types.OTHER);
throws 
--> setNull(i,Types.OTHER) is not supported; use
setObject(i,nullobject,Types.OTHER) instead.

st.setNull(2, Types.BINARY); // works
st.setNull(2, Types.VARCHAR); // works
The last two setNulls work, but are they a correct
solution?

Any hints?
Quirion

PS: Thanks to Markus Schraber, JDBC with PostGis is a
lot easier than ever!

__________________________________________________________
Lèche-vitrine ou lèche-écran ?
magasinage.yahoo.ca



More information about the postgis-users mailing list