pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Rob Hills <rob@netpaver.com.au>
To: pgsql-sql@postgresql.org
Subject: Re: How does postgres handle non literal string values
Date: Wed, 27 Nov 2002 01:18:02 +0800
Message-ID: <3DE41D4A.9268.9F992F@localhost> (raw)
In-Reply-To: <8adde2e2.0211250457.3f0d1c7c@posting.google.com>

Hi,

On 25 Nov 2002 at 4:57, javaholic wrote:

Your problem is really a JSP one rather than a postgres problem, and probably doesn't 
really belong on this list.  That said, I know much more java/jsp than I do postgres, so I'll 
try and help.

> 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.

Yup, your INSERT statement is doing exactly what you've asked it to do, inserting the 
literal strings 'username' and 'password' into the table.

> <%
>                         String insertString =
>                         "INSERT INTO  \"login\" (\'user\', \'password\')
> VALUES ('username', 'password')";
> %>

To do it correctly using JSP, try the following:

<% 
	String insertString = "INSERT INTO  \"login\" (\'user\', \'password\') 	
		VALUES ('" + username + "', '" + password + "')"; 
%>  

However, you would probably be better off using a PreparedStatement object rather 
than a Statement for various reasons, but especially to avoid trying to get the single- 
and double-quotes right in the above statement.

HTH,


Rob Hills
MBBS, Grad Dip Com Stud, MACS
Senior Consultant
Netpaver Web Solutions
Tel:	(0412) 904 357
Fax:	(08) 9485 2555
Email:	rob@netpaver.com.au




view thread (8+ messages)  latest in thread

Message-ID: <3DE41D4A.9268.9F992F@localhost>
Permalink:  ../3DE41D4A.9268.9F992F@localhost/
Also on:    postgresql.org/message-id/3DE41D4A.9268.9F992F@localhost

 · 

reply

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: rob@netpaver.com.au
  Subject: Re: How does postgres handle non literal string values
  In-Reply-To: <3DE41D4A.9268.9F992F@localhost>

* 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