Curious Curious - 1 month ago 6
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

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>>);