pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Dave Cramer <pg@fastcrypt.com>
To: Tobias Thierer <t_thierer@yahoo.de>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: escape string for pgsql (using jdbc/java)?
Date: Mon, 29 Jan 2007 18:38:35 -0500
Message-ID: <2473B100-9BC0-42F1-9CE5-02DF41E49569@fastcrypt.com> (raw)
In-Reply-To: <eplvti$2deb$1@news.hub.org>
References: <epbeqa$1g90$1@news.hub.org>
	<Pine.BSO.4.64.0701251936550.15719@leary2.csoft.net>
	<epgu2j$2jrk$1@news.hub.org>
	<45BD294D.5040002@opencloud.com>
	<eplvti$2deb$1@news.hub.org>


On 29-Jan-07, at 6:27 PM, Tobias Thierer wrote:

> Oliver Jowett wrote:
>
>> If you want something portable just use PreparedStatement.setString 
>> () and parameter placeholders. The "preparation" overhead you are  
>> worrying about is not really an issue as the PreparedStatement  
>> implementation is designed to handle one-shot queries as well as  
>> reused queries efficiently .. since PreparedStatement is often  
>> used just for parameter value interpolation to avoid exactly the  
>> issues you are encountering.
>
> I'm not so worried about the performance. But if I have a column of  
> type SERIAL in my table, then I can retrieve the generated value  
> using:
>
>  statement.executeUpdate(sqlString, Statement.RETURN_GENERATED_KEYS);
>  ResultSet resultSet = statement.getGeneratedKeys();
>  Integer result;
>  if (resultSet.next()) {
>    result = resultSet.getInt(1);
>  } else {
>    result = null;
>  }
>  resultSet.close();
>
You could if that worked in postgresql but getGeneratedKeys does not  
currently work
> whereas it is not clear to me how this works with a prepared  
> statement. Strangely, PreparedStatement extends Statement, so  
> PreparedStatement still has the executeUpdate(String,int) method -  
> but it is not clear to me whether this method will throw the  
> previously prepared statement away or what.
>
> Is there any easy way to retrieve the generated value for the  
> SERIAL column when using a prepared statement?
>
Yes, if it worked it would work with prepared statements.

Dave
>   Tobias
>
> ---------------------------(end of  
> broadcast)---------------------------
> TIP 5: don't forget to increase your free space map settings
>




view thread (10+ messages)  latest in thread

Message-ID: <2473B100-9BC0-42F1-9CE5-02DF41E49569@fastcrypt.com>
Permalink:  ../2473B100-9BC0-42F1-9CE5-02DF41E49569@fastcrypt.com/
Also on:    postgresql.org/message-id/2473B100-9BC0-42F1-9CE5-02DF41E49569@fastcrypt.com

 · 

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-jdbc@postgresql.org
  Cc: pg@fastcrypt.com, t_thierer@yahoo.de
  Subject: Re: escape string for pgsql (using jdbc/java)?
  In-Reply-To: <2473B100-9BC0-42F1-9CE5-02DF41E49569@fastcrypt.com>
  References: <epbeqa$1g90$1@news.hub.org> <Pine.BSO.4.64.0701251936550.15719@leary2.csoft.net> <epgu2j$2jrk$1@news.hub.org> <45BD294D.5040002@opencloud.com> <eplvti$2deb$1@news.hub.org> <2473B100-9BC0-42F1-9CE5-02DF41E49569@fastcrypt.com>

* 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