Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UOe8C-0002MM-An for pgsql-jdbc@arkaria.postgresql.org; Sun, 07 Apr 2013 01:10:52 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1UOe8B-0007WV-Jf for pgsql-jdbc@arkaria.postgresql.org; Sun, 07 Apr 2013 01:10:51 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UOe8B-0007WQ-0A for pgsql-jdbc@postgresql.org; Sun, 07 Apr 2013 01:10:51 +0000 Received: from sam.nabble.com ([216.139.236.26]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UOe85-0006wr-5y for pgsql-jdbc@postgresql.org; Sun, 07 Apr 2013 01:10:49 +0000 Received: from [192.168.236.26] (helo=sam.nabble.com) by sam.nabble.com with esmtp (Exim 4.72) (envelope-from ) id 1UOe84-0005tu-3m for pgsql-jdbc@postgresql.org; Sat, 06 Apr 2013 18:10:44 -0700 Date: Sat, 6 Apr 2013 18:10:44 -0700 (PDT) From: David Johnston To: pgsql-jdbc@postgresql.org Message-ID: <1365297044098-5751093.post@n5.nabble.com> In-Reply-To: <1365261492317-5751065.post@n5.nabble.com> References: <1365261492317-5751065.post@n5.nabble.com> Subject: Re: single quotation confusion MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: 1.8 (+) 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 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