Skip site navigation (1) Skip section navigation (2)

Re: PreparedStatement parameters question

From: Rene Pijlman <rene(at)lab(dot)applinet(dot)nl>
To: "Dr(dot) Evil" <drevil(at)sidereal(dot)kz>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: PreparedStatement parameters question
Date: 2001-10-21 12:04:31
Message-ID: mde5ttg5ckcbhtb7dvpiipvh6nulf94gb8@4ax.com (view raw or flat)
Thread:
Lists: pgsql-jdbc
On 20 Oct 2001 22:34:05 -0000, you wrote:
>PreparedStatement st = db.prepareStatement("UPDATE foo SET ? = '?' " +
>		  "WHERE number = ?");
>
>Whenever I use this I get a "Parameter index out of range" error.
>
>I am assuming that what this means is that I can't use a ? as a column
>name, but it can only be used as a parameter.  Am I correct in this?

You can only use ? parameters to supply values, not table names,
column names or syntactical elements of SQL.

>Should I basically do it like this:
>
>PreparedStatement st = db.prepareStatement("UPDATE foo SET " + colname
>		  + "= '?' WHERE number = ?");
>
>Is that the only way to do this?

Yes. I don't think you need the single quotes though.

Regards,
René Pijlman <rene(at)lab(dot)applinet(dot)nl>

In response to

pgsql-jdbc by date

Next:From: Rene PijlmanDate: 2001-10-21 12:06:21
Subject: Re: Does PG's JDBC support prepared statements at all?
Previous:From: Gunnar RønningDate: 2001-10-21 03:24:33
Subject: Re: [PATCHES] Ant configuration

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group