Hello all,
I'm a newbie. PostgreSQL 8.1.4. Fedora Core 5.
I'm writing a small java application that will import CSV txt files into
my DB. The SQL statement I'm sending to pgsql looks like this:
"INSERT into table (col1,col2,col3) values (to_number(?,
'999'),to_timestamp(?, 'MM/DD/YYYY HH24:MI:SS'),to_number(?, '9999');
Values are taken from a String array.
sometimes in col3 (smallint in pgsql DB) I need to insert a NULL value
but when I do I get the following error message:
invalid input syntax for type numeric: " "
I've search the archives and Internet and found similar situations but I
guess not experienced enough to fix this myself with info that I've
found.
Something like this:
Integer value1;
Date value2;
Integer value3;
PreparedStatement stmt = conn.prepareStatement(
"INSERT INTO table (col1,col2,col3) " +
"VALUES (?, ?, ?)"
);
int index = 1;
stmt.setInt(index++, value1.intValue());
stmt.setTimestamp(index++, new java.sql.Timestamp(value2.getTime()));
if (value3 == null) {
stmt.setNull(index++, Types.INTEGER);
} else {
stmt.setInt(index++, value3.intValue());
}
==================================================================
Aaron Bono
Aranya Software Technologies, Inc.
http://www.aranya.com
==================================================================