简体   繁体   中英

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 (?, ?)");

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

尝试这个

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM