update record with preparedstatement

Hi,
I want to update a record pass parameter by using something like preparedstatement
How can i do it,
recently i am updating like bellow
String sql = “UPDATE earn_money_app.app_configs SET code = '”+code+"’;
runner.update(sql);
And now i want to do like that
String sql = “UPDATE earn_money_app.app_configs SET code = ?”;
preparedstatement.setString(1,code);
preparedstatement.excecuteUpdate();

Thanks

In QueryRunner, you have variations of query() and update() methods accepting parameters. This methods use PreparedStatement under the hood.

You can also use plain JDBC to access the database if you want.

Auto-commit scenario:


DataSource dataSource = persistence.getDataSource();
Connection connection = dataSource.getConnection();
try {
    PreparedStatement preparedStatement = connection.prepareStatement("");
    preparedStatement.execute();
} finally {
    connection.close();
}

Transactional scenario:


try (Transaction tx = persistence.createTransaction()) {
    Connection connection = persistence.getEntityManager().getConnection();
    PreparedStatement preparedStatement = connection.prepareStatement("");
    preparedStatement.execute();
    tx.commit();
}