From: David Johnston <polobo@yahoo.com>
To: pgsql-jdbc@postgresql.org
Subject: Re: single quotation confusion
Date: Sat, 6 Apr 2013 18:10:44 -0700 (PDT)
Message-ID: <1365297044098-5751093.post@n5.nabble.com> (raw)
In-Reply-To: <1365261492317-5751065.post@n5.nabble.com>
References: <1365261492317-5751065.post@n5.nabble.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-jdbc>
R10 wrote
> i am connecting a postgresql database to a netbeans form , and when i try
> to execute a query which includes a string entered through a Jtextfield
> that contain the special charachter " ' " it reads it as a single
> quotation
> for example if a String txt = "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. You use a PREPARED STATEMENT with placeholders and then use the
setXXX methods to map the data.
SQL: INSERT INTO test VALUES (?)
Others may be able to provide more concrete suggestions but otherwise find
some books/articles on database programming in Java. This is not a
PostgreSQL specific topic/solution. I've known this for so long now I
really cannot point you to any educational materials.
David J.
--
View this message in context: http://postgresql.1045698.n5.nabble.com/single-quotation-confusion-tp5751065p5751093.html
Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com.
--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc
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: polobo@yahoo.com
Subject: Re: single quotation confusion
In-Reply-To: <1365297044098-5751093.post@n5.nabble.com>
References: <1365261492317-5751065.post@n5.nabble.com> <1365297044098-5751093.post@n5.nabble.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