Curious Curious - 1 year ago 63
Java Question

SQLite functions using PreparedStatement

How to use

SQLite
function using
PreparedStatement
?


PreparedStatement stmt;
String query = "insert into Test values(?,?)";
stmt = conection.prepareStatement(query);
stmt.setString(2, "date('now')");




date('now')
is the
SQLite
function I want to use, but it inserts "
date('now')
" as
Text
..

Answer Source

One way of achieving this is by changing your sql string, with this you may not need to set the date parameter anymore in your preparedstatement.

String query = "insert into Test values(?,date('now'))";

Now just you need to set the parameter 1

stmt.setString(1, <<param1 value>>);