Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UOqJg-0001Bv-AK for pgsql-jdbc@arkaria.postgresql.org; Sun, 07 Apr 2013 14:11:32 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1UOqJf-0008KL-Bz for pgsql-jdbc@arkaria.postgresql.org; Sun, 07 Apr 2013 14:11:31 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UOqJe-0008KD-F9 for pgsql-jdbc@postgresql.org; Sun, 07 Apr 2013 14:11:30 +0000 Received: from nm30-vm0.bullet.mail.bf1.yahoo.com ([98.139.213.126]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UOqJX-0002L8-AW for pgsql-jdbc@postgresql.org; Sun, 07 Apr 2013 14:11:29 +0000 Received: from [98.139.212.148] by nm30.bullet.mail.bf1.yahoo.com with NNFMP; 07 Apr 2013 14:11:22 -0000 Received: from [98.139.212.194] by tm5.bullet.mail.bf1.yahoo.com with NNFMP; 07 Apr 2013 14:11:22 -0000 Received: from [127.0.0.1] by omp1003.mail.bf1.yahoo.com with NNFMP; 07 Apr 2013 14:11:22 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 325954.81202.bm@omp1003.mail.bf1.yahoo.com Received: (qmail 92508 invoked by uid 60001); 7 Apr 2013 14:11:22 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ymail.com; s=s1024; t=1365343882; bh=jGl8HCXImFJy67UxeSZ6RAZ5HIQIfqeaCsclJEuf4xU=; h=X-YMail-OSG:Received:X-Rocket-MIMEInfo:X-Mailer:References:Message-ID:Date:From:Reply-To:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=EQq7aFKkBoSFAxBCIMcHn/KYiyOtsWHWounm7qg/76hDIw2ALqlmDwAfwPp5rK7urXDNbMkCAf3Tr/q2VSYOEnOiSJKIxM/g35Y1za4eZD/ecdZy/l+wrsOR/8Q22s5BOHRcfLI0YzIAO/VA9SxOq+OFz/Rs4ABXHVBM0BVaaCM= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=ymail.com; h=X-YMail-OSG:Received:X-Rocket-MIMEInfo:X-Mailer:References:Message-ID:Date:From:Reply-To:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=LSaS7wr9wDAg6LFaOw1qjZdPLAPluo2PkvL89uB6kiNHSbPupen33jPRfSLw29Orz9zPWGjMRPj4xjGUwjWLFBUjMeNXM0IGSXGxDAXvtiqWfXRlngQfXVeC3ipAJhusQm++yqhc2GmYHPG26zflZuQ9UuGgZTCcCJ4E3gpiDLQ=; X-YMail-OSG: JM3XA5oVM1m4nWIYqXU6xenVlLNIlT60I8k5Us7_z0czkHE 6g.eVTpfPReqq2gFuTkh.YnFucfyUy2R1CGXZTdj0eGwVhKYZVOwHFTO7TVH yLZXcR8AZKUlPgrUitK2sbpe.69HP6gxfSX2SjlUwTvvcqkiSBbGOHrR2FJG 8DwE_G3ou5nxbYpEcGsr1JgeY18g0Pi0jbfJ0gFkFJ_6XoYShWWEYZByVexT RvDwOiKNXdZopoYWQJsyzWkzSKWjbDagk3DUPPXq8hUC2lznEvy2KY00yTTR p8cvc5OZEhcsgN5f5ijnXJmSjHzQhI.7HmPuMGC1Po15GqLgOKjsoac330u_ byhXEc7rRLvWdKcaIzVK1_LKWBOddtKR_t6ZgjNpXmYDCrjjShSHauuUaj7Q AB7SSzaI6kt0HaIvVUX2NXnEZNySCAYfyiCxu56PyVlV1VH9OXLX3tP2yW5A 2ILzlLpjktH_8vPyi7bcH47xjQyD4sSPEz3ehnA8pKTFxwf1Ez7cmdyBjk5W Q3An0Ctkht7B.Z.UnYpJE_iP.JS698.tZ7p4Sr9xl8PsXmvNjMfm5xo_QwTi 9pxY_94k9JmLvsqZy6Wk- Received: from [76.255.18.237] by web162902.mail.bf1.yahoo.com via HTTP; Sun, 07 Apr 2013 07:11:22 PDT X-Rocket-MIMEInfo: 002.001, RGF2aWQgSm9obnN0b24gPHBvbG9ib0B5YWhvby5jb20.IHdyb3RlOgo.IFIxMCB3cm90ZQoKPj4gZm9yIGV4YW1wbGUgaWYgYSBTdHJpbmcgdHh0ID0gIml0J3MgY29sZCIgYW5kIHRvIGJlIGluc2VydGVkCj4.IGludG8gYSBzcWwgcXVlcnkgImluc2VydCBpbnRvIHRlc3QgdmFsdWVzICgnIit0eHQrIicpIjsKPj4gaXQgZ2l2ZXMgbWUKPj4gc3ludGF4IGVycm9yIGF0IG9yIG5lYXIgInMiCj4.Cj4.IGFueSBpZGVhcyBob3cgdG8gc29sdmUgdGhhdCBwcm9ibGVtID8_Cj4KPiBJbiBzaG9ydCB5b3UgZG8gbm8BMAEBAQE- X-Mailer: YahooMailWebService/0.8.140.532 References: <1365261492317-5751065.post@n5.nabble.com> <1365297044098-5751093.post@n5.nabble.com> Message-ID: <1365343882.92008.YahooMailNeo@web162902.mail.bf1.yahoo.com> Date: Sun, 7 Apr 2013 07:11:22 -0700 (PDT) From: Kevin Grittner Reply-To: Kevin Grittner Subject: Re: single quotation confusion To: David Johnston , "pgsql-jdbc@postgresql.org" In-Reply-To: <1365297044098-5751093.post@n5.nabble.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Pg-Spam-Score: -0.1 (/) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-jdbc Precedence: bulk Sender: pgsql-jdbc-owner@postgresql.org David Johnston wrote: > R10 wrote >> for example if a String txt =3D "it's cold" and to be inserted >> into a sql query "insert into test values ('"+txt+"')"; >> it gives me >> syntax error at or near "s" >> >> any ideas how to solve that problem ?? > > In short you do not build queries by directly concatenating > user-supplied data.=A0 You use a PREPARED STATEMENT with > placeholders and then use the setXXX methods to map the data. > > SQL: INSERT INTO test VALUES (?) Yeah, David's suggestion is the way to go.=A0 Trying to handle this in an ad hoc fashion opens you to a class of attack known as "SQL injection".=A0 When concatenating without proper handling of quotes (which drivers will do for you) you should consider yourself *lucky* if the worst you have seen is errors. http://xkcd.com/327/ The above link also illustrates why you shouldn't run the application under a user ID which has permission to execute DML. -- Kevin Grittner EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company --=20 Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-jdbc