pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Problem with PreparedStatement
4+ messages / 4 participants
[nested] [flat]

* Problem with PreparedStatement
@ 1999-10-18 17:05  Esteban Chiner Sanz <echiner@tissat.es>
  0 siblings, 2 replies; 4+ messages in thread

From: Esteban Chiner Sanz @ 1999-10-18 17:05 UTC (permalink / raw)
  To: pgsql-interfaces

I'm trying to do this:

if (counter != -1) /* No ha habido ningún error */
            {
                PreparedStatement pstmt=null;
                sql="insert into tar_historico values (?,?,?)";
                razon="<br>Query: " + sql;
                try {
                    pstmt = con.prepareStatement(sql);
                    pstmt.setString(1,Integer.toString(counter));
                    pstmt.setString(2,"1");
                    pstmt.setTimestamp(3,new Timestamp(new
java.util.Date().getTime()));
                    pstmt.executeUpdate(sql);
                    pstmt.close();
                    con.close();
                }

But I get this error message in the PostgreSQL log:

   query: insert into tar_historico values (?,?,?)
   ERROR:  parser: parse error at or near ","

What could be the problem? I've tried everything and I haven't found the
solution yet. Please, help.
Thanks in advance,

            Esteban Chiner
------------------------------------------------------------
 Esteban Chiner Sanz        mailto (work): echiner@tissat.es
 TISSAT
 Av. Aragon, 30, 5ª planta  Phone: 96 393 9950
 Valencia (SPAIN)





^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: [INTERFACES] Problem with PreparedStatement
@ 1999-10-18 18:22  Oliver Elphick <olly@lfix.co.uk>
  parent: Esteban Chiner Sanz <echiner@tissat.es>
  1 sibling, 0 replies; 4+ messages in thread

From: Oliver Elphick @ 1999-10-18 18:22 UTC (permalink / raw)
  To: Esteban Chiner Sanz <echiner@tissat.es>; +Cc: pgsql-interfaces

"Esteban Chiner Sanz" wrote:
  >I'm trying to do this:
  >
  >if (counter != -1) /* No ha habido ningún error */
  >            {
  >                PreparedStatement pstmt=null;
  >                sql="insert into tar_historico values (?,?,?)";
  >                razon="<br>Query: " + sql;
  >                try {
  >                    pstmt = con.prepareStatement(sql);
  >                    pstmt.setString(1,Integer.toString(counter));
  >                    pstmt.setString(2,"1");
  >                    pstmt.setTimestamp(3,new Timestamp(new
  >java.util.Date().getTime()));
  >                    pstmt.executeUpdate(sql);
  >                    pstmt.close();
  >                    con.close();
  >                }
  >
  >But I get this error message in the PostgreSQL log:
  >
  >   query: insert into tar_historico values (?,?,?)
  >   ERROR:  parser: parse error at or near ","
  >
  >What could be the problem? I've tried everything and I haven't found the
  >solution yet. Please, help.
  >Thanks in advance,
 
How about:
    sql="insert into tar_historico values ('?','?','?')";

-- 
      Vote against SPAM: http://www.politik-digital.de/spam/
                 ========================================
Oliver Elphick                                Oliver.Elphick@lfix.co.uk
Isle of Wight                              http://www.lfix.co.uk/oliver
               PGP key from public servers; key ID 32B8FAA1
                 ========================================
     "Delight thyself also in the LORD; and he shall give 
      thee the desires of thine heart."          Psalms 37:4





^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: [INTERFACES] Problem with PreparedStatement
@ 1999-10-19 17:16  Herouth Maoz <herouth@oumail.openu.ac.il>
  parent: Esteban Chiner Sanz <echiner@tissat.es>
  1 sibling, 1 reply; 4+ messages in thread

From: Herouth Maoz @ 1999-10-19 17:16 UTC (permalink / raw)
  To: Esteban Chiner Sanz <echiner@tissat.es>; pgsql-interfaces

At 19:05 +0200 on 18/10/1999, Esteban Chiner Sanz wrote:


> I'm trying to do this:
>
> if (counter != -1) /* No ha habido ningún error */
>             {
>                 PreparedStatement pstmt=null;
>                 sql="insert into tar_historico values (?,?,?)";
>                 razon="<br>Query: " + sql;
>                 try {
>                     pstmt = con.prepareStatement(sql);
>                     pstmt.setString(1,Integer.toString(counter));
>                     pstmt.setString(2,"1");
>                     pstmt.setTimestamp(3,new Timestamp(new
> java.util.Date().getTime()));
>                     pstmt.executeUpdate(sql);
>                     pstmt.close();
>                     con.close();
>                 }
>
> But I get this error message in the PostgreSQL log:
>
>    query: insert into tar_historico values (?,?,?)
>    ERROR:  parser: parse error at or near ","

What are the (Postgres) datatypes of the fields?

The best would be to know what the final format of the query became. For
this you have to run the postmaster with -d2 or something, to create a
debug-level log. It will show you the statements as they were passed to the
backend.

My personal suspicion is that your first two fields are numeric fields, not
string fields.

Herouth

--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma





^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: [INTERFACES] Problem with PreparedStatement
@ 1999-10-19 19:51  Peter Mount <peter@retep.org.uk>
  parent: Herouth Maoz <herouth@oumail.openu.ac.il>
  0 siblings, 0 replies; 4+ messages in thread

From: Peter Mount @ 1999-10-19 19:51 UTC (permalink / raw)
  To: Herouth Maoz <herouth@oumail.openu.ac.il>; +Cc: Esteban Chiner Sanz <echiner@tissat.es>; pgsql-interfaces

On Tue, 19 Oct 1999, Herouth Maoz wrote:

> At 19:05 +0200 on 18/10/1999, Esteban Chiner Sanz wrote:
> 
> 
> > I'm trying to do this:
> >
> > if (counter != -1) /* No ha habido ningún error */
> >             {
> >                 PreparedStatement pstmt=null;
> >                 sql="insert into tar_historico values (?,?,?)";
> >                 razon="<br>Query: " + sql;
> >                 try {
> >                     pstmt = con.prepareStatement(sql);
> >                     pstmt.setString(1,Integer.toString(counter));
> >                     pstmt.setString(2,"1");
> >                     pstmt.setTimestamp(3,new Timestamp(new
> > java.util.Date().getTime()));
> >                     pstmt.executeUpdate(sql);
> >                     pstmt.close();
> >                     con.close();
> >                 }
> >
> > But I get this error message in the PostgreSQL log:
> >
> >    query: insert into tar_historico values (?,?,?)
> >    ERROR:  parser: parse error at or near ","
> 
> What are the (Postgres) datatypes of the fields?
> 
> The best would be to know what the final format of the query became. For
> this you have to run the postmaster with -d2 or something, to create a
> debug-level log. It will show you the statements as they were passed to the
> backend.
> 
> My personal suspicion is that your first two fields are numeric fields, not
> string fields.

My suspicion aswell. Most people forget that setString() wraps the string
in quotes when the query is sent to the backend.

Peter

--
       Peter T Mount peter@retep.org.uk
      Main Homepage: http://www.retep.org.uk
PostgreSQL JDBC Faq: http://www.retep.org.uk/postgres
 Java PDF Generator: http://www.retep.org.uk/pdf




^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~1999-10-19 19:51 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1999-10-18 17:05 Problem with PreparedStatement Esteban Chiner Sanz <echiner@tissat.es>
1999-10-18 18:22 ` Oliver Elphick <olly@lfix.co.uk>
1999-10-19 17:16 ` Herouth Maoz <herouth@oumail.openu.ac.il>
1999-10-19 19:51   ` Peter Mount <peter@retep.org.uk>

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