Example usage for org.apache.commons.dbutils GenKeyQueryRunner GenKeyQueryRunner

List of usage examples for org.apache.commons.dbutils GenKeyQueryRunner GenKeyQueryRunner

Introduction

In this page you can find the example usage for org.apache.commons.dbutils GenKeyQueryRunner GenKeyQueryRunner.

Prototype

public GenKeyQueryRunner(boolean pmdKnownBroken, ResultSetHandler<T> keyHandler) 

Source Link

Document

Construct a new GenKeyQueryRunner using the given handler, which will let JDBC decide on its own the key columns to use for auto-generated keys retrieval

Usage

From source file:ttf.persistence.sql.ArticleSaver.java

private void insert(Article article) throws SQLException {
    GenKeyQueryRunner<String> run;
    run = new GenKeyQueryRunner<String>(dataSource, new IdResultHandler());

    String sql = "INSERT INTO Articles"
            + " (address, title, author, publishedAt, discoveredAt, content, topicId)"
            + " VALUES (?, ?, ?, ?, ?, ?, ?)";

    run.update(sql, //
            article.getAddress(), //
            article.getTitle(), //
            article.getAuthor(), //
            article.getDiscoveredAt(), //
            article.getDiscoveredAt(), //
            article.getContent(), //
            article.getTopic().getId());

    String id = run.getGeneratedKeys();
    article.setId(id);//from  w w w  . j  a v a  2  s  .  com
}

From source file:ttf.persistence.sql.TopicSaver.java

private void insert(Topic topic) throws SQLException {
    GenKeyQueryRunner<String> run;
    run = new GenKeyQueryRunner<String>(dataSource, new IdResultHandler());

    String sql = "INSERT INTO Topics (title) VALUES (?)";
    run.update(sql, topic.getTitle());//  ww  w.j  a  v  a  2 s . c  om
    String id = run.getGeneratedKeys();
    topic.setId(id);
}