Re: [INTERFACES] Problem with PreparedStatement

From: Peter Mount <peter(at)retep(dot)org(dot)uk>
To: Herouth Maoz <herouth(at)oumail(dot)openu(dot)ac(dot)il>
Cc: Esteban Chiner Sanz <echiner(at)tissat(dot)es>, pgsql-interfaces(at)postgresql(dot)org
Subject: Re: [INTERFACES] Problem with PreparedStatement
Date: 1999-10-19 19:51:13
Message-ID: Pine.LNX.4.10.9910192050140.9738-100000@maidast.retep.org.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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 ningn 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(at)retep(dot)org(dot)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

In response to

Browse pgsql-interfaces by date

  From Date Subject
Next Message Jim Lemon 1999-10-20 03:02:18 PgAccess unable to start
Previous Message Herouth Maoz 1999-10-19 17:16:51 Re: [INTERFACES] Problem with PreparedStatement