Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 916A247649F for ; Tue, 26 Nov 2002 10:45:10 -0500 (EST) Received: from anchor-post-39.mail.demon.net (anchor-post-39.mail.demon.net [194.217.242.80]) by postgresql.org (Postfix) with ESMTP id 0C44447641E for ; Tue, 26 Nov 2002 10:45:09 -0500 (EST) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-39.mail.demon.net with esmtp (Exim 3.36 #2) id 18Ghtb-0003ze-0U; Tue, 26 Nov 2002 15:45:08 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by mainbox.archonet.com (Postfix) with ESMTP id B5AAC17507; Tue, 26 Nov 2002 15:35:05 +0000 (GMT) Received: from client.archonet.com (client.archonet.com [192.168.1.16]) by mainbox.archonet.com (Postfix) with ESMTP id 25E9D17506; Tue, 26 Nov 2002 15:35:05 +0000 (GMT) Content-Type: text/plain; charset="iso-8859-1" From: Richard Huxton Organization: Archonet Ltd To: monroy@mindspring.com (javaholic), pgsql-sql@postgresql.org Subject: Re: How does postgres handle non literal string values Date: Tue, 26 Nov 2002 15:35:02 +0000 User-Agent: KMail/1.4.3 References: <8adde2e2.0211250457.3f0d1c7c@posting.google.com> In-Reply-To: <8adde2e2.0211250457.3f0d1c7c@posting.google.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200211261535.02419.dev@archonet.com> X-Virus-Scanned: by AMaViS snapshot-20020531 X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200211/394 X-Sequence-Number: 10536 On Monday 25 Nov 2002 12:57 pm, javaholic wrote: > Hi All, > > I have some jsp code that should insert a user name and password into > a table called login. > > Instead of inserting the values given by the client, it insert the > literal string 'username' and 'password. The problem is somewhere in > the INSERT statement. > String insertString =3D > "INSERT INTO \"login\" (\'user\', \'password\') > VALUES ('username', 'password')"; You're creating an insertString with the literal words "username" and=20 "password" in them. This is a java issue, not a PG issue. You'll want=20 something like (sorry if syntax is wrong, but I don't do Java): String insertString =3D "Insert INTO ... VALUES ('" + sql_escaped(username)= +=20 "')..." You *will* want to escape the username and password otherwise I'll be able = to=20 come along and insert any values I like into your database. I can't believe= =20 the JDBC classes don't provide=20 1. Some way to escape value strings 2. Some form of placeholders to deal with this --=20 Richard Huxton