Обсуждение: Throwing NumberFormat exception for preparedStatement.setObjcet()
Hi,
In our application we are using the Postgres Sql 8.3.3 and jdbc driver is postgresql-8.0-310.jdbc3.
When I am trying to set the value for id(int) like as follows throwing exception.
ps.setObject(1, inputData,columntype);
where inputdate value is 2
if I modified the above statement like as follows then it works fine.
ps.setObject(1, inputData);
I want to know what could be the proble.
Thanks,
Srinvias
DISCLAIMER ========== This e-mail may contain privileged and confidential information which is the property of Persistent Systems Ltd. It is intended only for the use of the individual or entity to which it is addressed. If you are not the intended recipient, you are not authorized to read, retain, copy, print, distribute or use this message. If you have received this communication in error, please notify the sender and delete all copies of this message. Persistent Systems Ltd. does not accept any liability for virus infected mails.
On Mon, Jan 11, 2010 at 7:58 AM, Srinivas Gunnam <srinivas_gunnam@persistent.co.in> wrote: > Hi, > > In our application we are using the Postgres Sql 8.3.3 and jdbc driver is > postgresql-8.0-310.jdbc3. Do you mean 8.0-310 ? if so why not use a more recent driver ? > > > > When I am trying to set the value for id(int) like as follows throwing > exception. > > ps.setObject(1, inputData,columntype); > > where inputdate value is 2 what is the columnType value ? Dave
> > > Hi, > > In our application we are using the Postgres Sql 8.3.3 and jdbc driver > is postgresql-8.0-310.jdbc3. > > When I am trying to set the value for id(int) like as follows > throwing exception. > ps.setObject(1, inputData,columntype); > where inputdate value is 2 > if I modified the above statement like as follows then it works fine. > ps.setObject(1, inputData); > I want to know what could be the proble. > > Thanks, > > Srinvias It looks like you to me off hand that the targetSqlType may possibly not be a ROWID per the documentation. Also maybe check that value, columntype, to insure matches. =================================================================== setObject void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException Sets the value of the designated parameter with the given object. This method is like the method setObject above, except that it assumes a scale of zero. Parameters: parameterIndex - the first parameter is 1, the second is 2, ... x - the object containing the input parameter value targetSqlType - the SQL type (as defined in java.sql.Types) to be sent to the database Throws: SQLException - if parameterIndex does not correspond to a parameter marker in the SQL statement; if a database access error occurs or this method is called on a closed PreparedStatement SQLFeatureNotSupportedException - if targetSqlType is a ARRAY, BLOB, CLOB, DATALINK, JAVA_OBJECT, NCHAR, NCLOB, NVARCHAR, LONGNVARCHAR, REF, ROWID, SQLXML or STRUCT data type and the JDBC driver does not support this data type See Also: Types =================================================================== danap.
Thanks for your reply. Here columnType value is 3 and inputdata value is always string type. -----Original Message----- From: davecramer@gmail.com [mailto:davecramer@gmail.com] On Behalf Of Dave Cramer Sent: Tuesday, January 12, 2010 1:45 AM To: Srinivas Gunnam Cc: pgsql-jdbc@postgresql.org Subject: Re: [JDBC] Throwing NumberFormat exception for preparedStatement.setObjcet() On Mon, Jan 11, 2010 at 7:58 AM, Srinivas Gunnam <srinivas_gunnam@persistent.co.in> wrote: > Hi, > > In our application we are using the Postgres Sql 8.3.3 and jdbc driver is > postgresql-8.0-310.jdbc3. Do you mean 8.0-310 ? if so why not use a more recent driver ? > > > > When I am trying to set the value for id(int) like as follows throwing > exception. > > ps.setObject(1, inputData,columntype); > > where inputdate value is 2 what is the columnType value ? Dave DISCLAIMER ========== This e-mail may contain privileged and confidential information which is the property of Persistent Systems Ltd. It is intendedonly for the use of the individual or entity to which it is addressed. If you are not the intended recipient, youare not authorized to read, retain, copy, print, distribute or use this message. If you have received this communicationin error, please notify the sender and delete all copies of this message. Persistent Systems Ltd. does not acceptany liability for virus infected mails.
On Tue, Jan 12, 2010 at 12:40 AM, Srinivas Gunnam <srinivas_gunnam@persistent.co.in> wrote: > > > Thanks for your reply. > Here columnType value is 3 and inputdata value is always string type. If I were writing it I would use java.sql.Types.Integer as the columnType, not the numeric value. And inputData should be an Integer. Dave > -----Original Message----- > From: davecramer@gmail.com [mailto:davecramer@gmail.com] On Behalf Of Dave Cramer > Sent: Tuesday, January 12, 2010 1:45 AM > To: Srinivas Gunnam > Cc: pgsql-jdbc@postgresql.org > Subject: Re: [JDBC] Throwing NumberFormat exception for preparedStatement.setObjcet() > > On Mon, Jan 11, 2010 at 7:58 AM, Srinivas Gunnam > <srinivas_gunnam@persistent.co.in> wrote: >> Hi, >> >> In our application we are using the Postgres Sql 8.3.3 and jdbc driver is >> postgresql-8.0-310.jdbc3. > > > Do you mean 8.0-310 ? if so why not use a more recent driver ? > >> >> >> >> When I am trying to set the value for id(int) like as follows throwing >> exception. >> >> ps.setObject(1, inputData,columntype); >> >> where inputdate value is 2 > > what is the columnType value ? > > Dave > > DISCLAIMER > ========== > This e-mail may contain privileged and confidential information which is the property of Persistent Systems Ltd. It isintended only for the use of the individual or entity to which it is addressed. If you are not the intended recipient,you are not authorized to read, retain, copy, print, distribute or use this message. If you have received thiscommunication in error, please notify the sender and delete all copies of this message. Persistent Systems Ltd. doesnot accept any liability for virus infected mails. >
On Tue, 12 Jan 2010, Dave Cramer wrote: > If I were writing it I would use java.sql.Types.Integer as the > columnType, not the numeric value. And inputData should be an Integer. > inputData can perfectly well be a String. That's the whole point of the three argument version of this method, to provide such a conversion for the user. The reason it's throwing a NumberFormatException is that you're passing something which isn't a number. With a later driver version you wouldn't get this exception, but instead the server would complain that it wasn't a valid number. The attached test case shows this working just fine from my perspective. Kris Jurka
Вложения
Thanks all, Problem resolved :) -----Original Message----- From: Kris Jurka [mailto:books@ejurka.com] Sent: Thursday, January 14, 2010 4:07 AM To: Dave Cramer Cc: Srinivas Gunnam; pgsql-jdbc@postgresql.org Subject: Re: [JDBC] Throwing NumberFormat exception for preparedStatement.setObjcet() On Tue, 12 Jan 2010, Dave Cramer wrote: > If I were writing it I would use java.sql.Types.Integer as the > columnType, not the numeric value. And inputData should be an Integer. > inputData can perfectly well be a String. That's the whole point of the three argument version of this method, to provide such a conversion for the user. The reason it's throwing a NumberFormatException is that you're passing something which isn't a number. With a later driver version you wouldn't get this exception, but instead the server would complain that it wasn't a valid number. The attached test case shows this working just fine from my perspective. Kris Jurka DISCLAIMER ========== This e-mail may contain privileged and confidential information which is the property of Persistent Systems Ltd. It is intendedonly for the use of the individual or entity to which it is addressed. If you are not the intended recipient, youare not authorized to read, retain, copy, print, distribute or use this message. If you have received this communicationin error, please notify the sender and delete all copies of this message. Persistent Systems Ltd. does not acceptany liability for virus infected mails.