pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Richard Huxton <dev@archonet.com>
To: monroy@mindspring.com
To: pgsql-sql@postgresql.org
Subject: Re: How does postgres handle non literal string values
Date: Tue, 26 Nov 2002 15:35:02 +0000
Message-ID: <200211261535.02419.dev@archonet.com> (raw)
In-Reply-To: <8adde2e2.0211250457.3f0d1c7c@posting.google.com>
References: <8adde2e2.0211250457.3f0d1c7c@posting.google.com>

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 =
>                         "INSERT INTO  \"login\" (\'user\', \'password\')
> VALUES ('username', 'password')";

You're creating an insertString with the literal words "username" and 
"password" in them. This is a java issue, not a PG issue. You'll want 
something like (sorry if syntax is wrong, but I don't do Java):

String insertString = "Insert INTO ... VALUES ('" + sql_escaped(username) + 
"')..."

You *will* want to escape the username and password otherwise I'll be able to 
come along and insert any values I like into your database. I can't believe 
the JDBC classes don't provide 

1. Some way to escape value strings
2. Some form of placeholders to deal with this

-- 
  Richard Huxton



view thread (8+ messages)  latest in thread

Message-ID: <200211261535.02419.dev@archonet.com>
Permalink:  ../200211261535.02419.dev@archonet.com/
Also on:    postgresql.org/message-id/200211261535.02419.dev@archonet.com

 · 

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: dev@archonet.com, monroy@mindspring.com
  Subject: Re: How does postgres handle non literal string values
  In-Reply-To: <200211261535.02419.dev@archonet.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