You can use QueryRunner#insert() . The following is an example. For a table called users that has an auto-generated primary key column and a varchar column called username , you can do something like this:
DataSource dataSource = ... // however your app normally gets a DataSource QueryRunner queryRunner = new QueryRunner(dataSource); String sql = "insert into users (username) values (?)"; long userId = queryRunner.insert(sql, new ScalarHandler<Long>(), "test");
Asaph source share