dbTalk Databases Forums  

[BUGS] BUG #6445: PreparedStatement.setObject(1,java.util.String)

mailing.database.pgsql-bugs mailing.database.pgsql-bugs


Discuss [BUGS] BUG #6445: PreparedStatement.setObject(1,java.util.String) in the mailing.database.pgsql-bugs forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
rajesh4.t@tcs.com
 
Posts: n/a

Default [BUGS] BUG #6445: PreparedStatement.setObject(1,java.util.String) - 02-08-2012 , 01:05 PM






The following bug has been logged on the website:

Bug reference: 6445
Logged by: Rajesh
Email address: rajesh4.t (AT) tcs (DOT) com
PostgreSQL version: 8.4.3
Operating system: Windows XP
Description:


I have a table in PostgreSQL database

CREATE TABLE newtest
(
id numeric(6),
name character varying(120),
email character varying(120)
)

I am using PreparedStatement so that i can insert data into newtest table

INSERT INTO NewTest (ID,NAME,EMAIL ) values (?,?,? )

Actual query fired -INSERT INTO NewTest (ID,NAME,EMAIL ) values ('1','Rajesh
','rajesh4.t (AT) abs (DOT) com' )

code for prepared statement

try{
pstatement=conn.prepareStatement(insertQuery);
for(int k=1;k<rows;k++){
pstatement.clearParameters();
Cell datacell[]=sheets[i].getRow(k);
for(int
eachCell=0;eachCell<columnNames.size();eachCell++) {
pstatement.setObject(eachCell+1,
datacell[eachCell].getContents());
}
pstatement.addBatch();
}
pstatement.executeBatch();
pstatement.close();
}catch(Exception er){
LOG.error("Failed to set Row data for tableName:
"+tableName,er);
throw new DbComparisonException(er);
}

Please note I am reading data from an excel sheet and
datacell[eachCell].getContents() is of type String..prepareStatement
setObject is complaining that I am sending String datatype which cannot be
casted to bigint or numeric,but that is the job of setObject right to decide
the target datatype and cast accordingly..please reply any
solution..Parameter to setObject(can be anything) so I cannot cast the data
to appropriate format before sending the data


--
Sent via pgsql-bugs mailing list (pgsql-bugs (AT) postgresql (DOT) org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.