how to insert mysql function into query in java

Hello,

i've got a problem here :

i try to use mysql function NOW() for example:

sql query is

INSERT INTO users (NAME,TIME) values("John", NOW() )

In java i use bean to connect to DB

String query="INSERT INTO users (NAME,TIME) values('john','now()')";

dbaccess.statement.executeUpdate(query);

but it doesn't work, it is because there is function NOW() with special characters () how can i solve this problem ?

i tried to use

String query="INSERT INTO users (NAME,TIME) values('john','now/(/)')";

String query="INSERT INTO users (NAME,TIME) values('john','now\(\)')";

but nothing works,

Thanks in advance

[706 byte] By [Jarkoa] at [2007-11-26 20:16:59]
# 1
Try PreparedStatement.
jverda at 2007-7-10 0:39:57 > top of Java-index,Java Essentials,Java Programming...
# 2
I would try now() instead of 'now()'
n3bul4a at 2007-7-10 0:39:57 > top of Java-index,Java Essentials,Java Programming...
# 3

> Hello,

> i've got a problem here :

>

> i try to use mysql function NOW() for example:

> sql query is

> INSERT INTO users (NAME,TIME) values("John", NOW() )

> n java i use bean to connect to DB

>

> String query="INSERT INTO users (NAME,TIME)

> values('john','now()')";

> dbaccess.statement.executeUpdate(query);

>

It has nothing to do with the function.

Ticks create a text literal. You haven't called a function you have instead create a literal.

The solution is don't use ticks around the function.

jschella at 2007-7-10 0:39:57 > top of Java-index,Java Essentials,Java Programming...
# 4
thx, it works fine
Jarkoa at 2007-7-10 0:39:57 > top of Java-index,Java Essentials,Java Programming...