Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 4491C9FB3DA for ; Mon, 29 Jan 2007 19:38:38 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-new, port 10024) with ESMTP id 38932-04 for ; Mon, 29 Jan 2007 19:38:30 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from net2.micro-automation.com (net2.micro-automation.com [64.7.141.29]) by postgresql.org (Postfix) with SMTP id 987EE9FB3D2 for ; Mon, 29 Jan 2007 19:38:34 -0400 (AST) Received: (qmail 11209 invoked from network); 29 Jan 2007 23:38:32 -0000 Received: from dcdsl.ebox.com (HELO ?192.168.1.14?) (davec@64.7.143.116) by net2.micro-automation.com with SMTP; 29 Jan 2007 23:38:32 -0000 In-Reply-To: References: <45BD294D.5040002@opencloud.com> Mime-Version: 1.0 (Apple Message framework v752.3) Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: <2473B100-9BC0-42F1-9CE5-02DF41E49569@fastcrypt.com> Cc: pgsql-jdbc@postgresql.org Content-Transfer-Encoding: 7bit From: Dave Cramer Subject: Re: escape string for pgsql (using jdbc/java)? Date: Mon, 29 Jan 2007 18:38:35 -0500 To: Tobias Thierer X-Mailer: Apple Mail (2.752.3) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200701/181 X-Sequence-Number: 16546 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 >