Prepared statement and SQL functions



Hi,

I'm using a PreparedStatement for an INSERT operation and can set the values
of ints and strings using the .set* methods.

But some of the parameters are function calls to be executed at the database
server.

Example: I want to end up with:

"INSERT INTO table ( id, name, last_update ) VALUES ( 1, 'Fred', NOW() )"

[ NOW() is a MySQL function that returns the current date ]


PreparedStatement ps = conn.prepareStatement(
"INSERT INTO table ( id, name, last_update ) VALUES ( ?, ?, ? )" );

ps.setInt( 1, new Integer( 1 ) );
ps.setString( 2, new String( "Fred" ) );

.... What do I do for parameter 3?


Thanks for any help.

--
Regards,
Steve

"...which means he created the heaven and the earth... in the DARK! How good
is that?"

.



Relevant Pages

  • Re: Prepared statement and SQL functions
    ... I'm using a PreparedStatement for an INSERT operation and can set the values ... of ints and strings using the .set* methods. ... [NOWis a MySQL function that returns the current date] ...
    (comp.lang.java.databases)
  • Re: Prepared statement and SQL functions
    ... [NOWis a MySQL function that returns the current date] ... PreparedStatement ps = conn.prepareStatement( ... array. ... You don't need to explicitly construct a String object here. ...
    (comp.lang.java.databases)
  • Re: Statement and Resultset
    ... strings. ... protection against SQL injection security hacks. ... So how does one avoid the overhead of a PreparedStatement when Statement incurs it anyway? ... Moreover it is a more complex resource, as a PreparedStatement must be able to replace the ?'s with passed parameters. ...
    (comp.lang.java.programmer)