Curious
Curious

Reputation: 109

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..

Upvotes: 0

Views: 352

Answers (1)

mhasan
mhasan

Reputation: 3709

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

Upvotes: 3

Related Questions