Re: How does postgres handle non literal string values

From: Doug McNaught <doug(at)mcnaught(dot)org>
To: monroy(at)mindspring(dot)com (javaholic)
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: How does postgres handle non literal string values
Date: 2002-11-27 15:25:47
Message-ID: m3fztndog4.fsf@varsoon.wireboard.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

monroy(at)mindspring(dot)com (javaholic) writes:

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

First, your SQL syntax is wrong (field names in an INSERT shouldn't be
quoted), and second, Java isn't Perl--it won't magically interpolate
variable values into a string. Try:

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

This will work but has a gaping security hole. Even better, use a
PreparedStatement instead--it's much cleaner and is immune to SQL
injection attacks.

-Doug

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Ken Guest 2002-11-27 15:43:10 [Fwd: rename]
Previous Message Loeke 2002-11-27 15:17:42 template0 1 psql -d .. (newbie)