Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 8A0349FB3C9 for ; Mon, 29 Jan 2007 19:27:54 -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 36543-08 for ; Mon, 29 Jan 2007 19:27:44 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from floppy.pyrenet.fr (floppy.pyrenet.fr [194.116.145.2]) by postgresql.org (Postfix) with ESMTP id 3C0679FB3C5 for ; Mon, 29 Jan 2007 19:27:48 -0400 (AST) Received: by floppy.pyrenet.fr (Postfix, from userid 106) id DED5130E32; Tue, 30 Jan 2007 00:27:46 +0100 (MET) From: Tobias Thierer X-Newsgroups: pgsql.interfaces.jdbc Subject: Re: escape string for pgsql (using jdbc/java)? Date: Tue, 30 Jan 2007 12:27:48 +1300 Organization: Hub.Org Networking Services Lines: 31 Message-ID: References: <45BD294D.5040002@opencloud.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@news.hub.org User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.9) Gecko/20061211 SeaMonkey/1.0.7 In-Reply-To: <45BD294D.5040002@opencloud.com> To: pgsql-jdbc@postgresql.org X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.001 tagged_above=0 required=5 tests=BAYES_50 X-Spam-Level: X-Archive-Number: 200701/180 X-Sequence-Number: 16545 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(); 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? Tobias