List:MySQL and Java« Previous MessageNext Message »
From:Mark Matthews Date:April 29 1999 5:06pm
Subject:RE: insert variables
View as plain text  
> -----Original Message-----
> From: or36@stripped [mailto:or36@stripped]
> Sent: Thursday, April 29, 1999 12:01 PM
> To: java@stripped
> Subject: insert variables
> Hi!
> I am having difficulty creating an insert statement in Java that would
> use variable values as the values parameters.
> None of the following worked -- I would get either the name of the
> variable instead of the value or nothing at all:
> String value1 = new String("blah");
> insert into table values (value1);
>  or
> insert into table values ('value1');
>  or
> insert into table values ("value1");
>  or
> insert into table values (\'value1\');
>  or
> insert into table values (\"value1\");
> The context in which I need to use this is more complex than building an
> object string from a known value.

There are two ways to do this. You can do:

	String SQL = "insert into table values ('" + value1 + "')";

	PreparedStatement PStmt = Connex.prepareStatement("insert into table values
	PStmt.setString(1, "Some Value");

Java and JDBC do not do inline variable expansion like some variants of
embedded SQL, or Perl, so you have to use one of the above two methods.


insert variablesOana Radulescu29 Apr
  • RE: insert variablesMark Matthews29 Apr
  • Re: insert variablesRITESH BISWAS30 Apr
    • Re: insert variablesAmbrose Li30 Apr
      • Re: insert variablesmmatthew30 Apr
      • Re: insert variablesTim Endres30 Apr