user3290180
user3290180

Reputation: 4410

JDBC: how to perform functions inside a prepared statement?

With this query

  INSERT INTO `schema`.`table` (`col1`, `col2`) 
  VALUES ('value1', unhex(sha2("value2", 256)));

how to prepare a statement for the jdbc driver with one value produced by those functions?

 preparedStatement = connect.prepareStatement("insert into schema.table values (?, ?)");

Upvotes: 0

Views: 2340

Answers (2)

Rajesh Jangid
Rajesh Jangid

Reputation: 724

Use the following format to get the job done.

preparedStatement = connect.prepareStatement("insert into schema.table values (?, unhex(sha2(?,256)))");

preparedStatement.setString(1, "value1");
preparedStatement.setString(2, "value2");

Upvotes: 4

Arjun
Arjun

Reputation: 3793

Try this

preparedStatement = connect.prepareStatement("insert into schema.table values (?, unhex(sha2(?, 256)))");

Upvotes: 1

Related Questions