Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 7EE089FB2E8 for ; Sun, 28 Jan 2007 18:46:45 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-new, port 10024) with ESMTP id 12757-04 for ; Sun, 28 Jan 2007 18:46:38 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 33BF19FA372 for ; Sun, 28 Jan 2007 18:46:42 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.3 Received: from yass.opencloud.co.nz (yass.opencloud.co.nz [131.203.101.226]) by svr4.postgresql.org (Postfix) with ESMTP id B1BB95AF980 for ; Sun, 28 Jan 2007 22:46:37 +0000 (GMT) Received: from [219.89.217.179] (helo=[10.1.1.3]) by yass.opencloud.co.nz with asmtp (TLS-1.0:DHE_RSA_AES_128_CBC_SHA:16) (Exim 4.34) id 1HBIn4-00081D-IM; Mon, 29 Jan 2007 11:46:27 +1300 Message-ID: <45BD294D.5040002@opencloud.com> Date: Sun, 28 Jan 2007 22:53:01 +0000 From: Oliver Jowett User-Agent: Mozilla Thunderbird 0.8 (Windows/20040913) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Tobias Thierer Cc: pgsql-jdbc@postgresql.org Subject: Re: escape string for pgsql (using jdbc/java)? References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Broken-Reverse-DNS: no host name found for IP address 219.89.217.179 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.42 tagged_above=0 required=5 tests=AWL, BAYES_60 X-Spam-Level: X-Archive-Number: 200701/179 X-Sequence-Number: 16544 Tobias Thierer wrote: > Kris Jurka wrote: > >>> 1.) Is there a built-in method somewhere in the jdbc driver that >>> escapes >>> strings and makes them safe to use in an SQL statement (inside a >>> string)? >> >> >> There is org.postgresql.core.Utils#appendEscapedString, but it's not >> something we support or advertise. It's really for internal use only. > > > I dislike that this method expects me to tell it whether i have > standard_conforming_strings set - this kinda defeats the "write once, > run everywhere" principle. 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. -O