pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: rajesh4.t@tcs.com
To: pgsql-bugs@postgresql.org
Subject: BUG #6445: PreparedStatement.setObject(1,java.util.String)
Date: Wed, 08 Feb 2012 19:05:59 +0000
Message-ID: <E1RvCq7-0003Fi-RK@wrigleys.postgresql.org> (raw)

The following bug has been logged on the website:

Bug reference:      6445
Logged by:          Rajesh
Email address:      rajesh4.t@tcs.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@abs.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




view thread (2+ messages)  latest in thread

Message-ID: <E1RvCq7-0003Fi-RK@wrigleys.postgresql.org>
Permalink:  ../E1RvCq7-0003Fi-RK@wrigleys.postgresql.org/
Also on:    postgresql.org/message-id/E1RvCq7-0003Fi-RK@wrigleys.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: rajesh4.t@tcs.com
  Subject: Re: BUG #6445: PreparedStatement.setObject(1,java.util.String)
  In-Reply-To: <E1RvCq7-0003Fi-RK@wrigleys.postgresql.org>
  References: <E1RvCq7-0003Fi-RK@wrigleys.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox