Possible to say: [setObject("123")] to insert into int column type ?

From: "j(dot)random(dot)programmer" <javadesigner(at)yahoo(dot)com>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Possible to say: [setObject("123")] to insert into int column type ?
Date: 2006-06-28 22:46:05
Message-ID: 20060628224605.94631.qmail@web32014.mail.mud.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Hi:

I think setObject() has been discussed extensively on
this list
(particularly with setting null values). However,
consider the following:

In PSQL:
test=# create table foo (number_column int);

Now in Java:
PreparedStatement ps = con.prepareStatement(
"insert into foo (number_column) values (?)"
);
ps.setObject(1, "123");
ps.executeUpdate();

This will throw a Driver exception. Is this expected
behavior
or should the driver do a Integer.parseInt(...) on the
string value
as needed ?

This is not a show-stopper or even a serious bug in my
code
and is easy to workaround. I'm just curious as to the
"right"
behavior as per the JDBC spec.....

Best regards,
--j

----------------------- Exception ------------------

ERROR: column "number_column" is of type integer but
expression is of type character varying
at
org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(
QueryExecutorImpl.java:1527)
at
org.postgresql.core.v3.QueryExecutorImpl.processResults(
QueryExecutorImpl.java:1311)
.....
---------------------------------------------------

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Oliver Jowett 2006-06-29 00:55:37 Re: Possible to say: [setObject("123")] to insert into int
Previous Message Vijay Kiran Kamuju 2006-06-28 22:37:38 Re: Postgresql 7.4.1 and jdbc errors