(Continue this thread on the INTERFACES list, where it belongs)
At 2:46 +0200 on 18/2/99, Peter Garner wrote:
> Hi Atika! :-)
> > I am basically trying to do something like this:
> > String input = "This is a String";
> > myConn.updateQuery("insert into myDB values(input)");
> > but get an error when I run it saying:
> > ERROR: attribute input not found
> > java.sql.SQLException: ERROR: attribute input not found
> String input = "This is a String"
> String query = insert into myDB value ('" + input + "')"
Ahem. No, this may work, but that's not the way to go about it. In any
case, where did that "updateQuery" come from?
Atika, I have a feeling you are not well-acquainted with JDBC. Reccomended
(All on the same line. Not my fault the URLs are that long at Javasoft).
The basic idea is to use a PreparedStatement. These statements include
placeholders, which you fill before you execute them. This enables you to
(a) reuse the same statements with different values, (b) use things other
than strings and (c) have the strings properly quoted and escaped for you.
PreparedStatement stmt =
myConn.prepareStatement( "INSERT INTO myDB VALUES ( ? ) " );
String input = "This is a string";
stmt.setString( 1, input );
Note that Peter's solution would not have worked if your input was:
String input = "It's a beautiful day today."
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
In response to
pgsql-interfaces by date
|Next:||From: Justin R. Smith||Date: 1999-02-21 16:03:15|
|Subject: Quotes in input|
|Previous:||From: Michael Meskes||Date: 1999-02-21 11:54:37|
|Subject: Re: [INTERFACES] ecpg idea|
pgsql-sql by date
|Next:||From: Werner Reisberger||Date: 1999-02-21 17:38:10|
|Subject: triggers (refint)|
|Previous:||From: Thomas G. Lockhart||Date: 1999-02-20 16:17:19|
|Subject: Re: [HACKERS] Re: [SQL] SQL-Query 2 get primary key|