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

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

Introduction

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

Prototype

public T getGeneratedKeys() 

Source Link

Document

Returns the generated keys, generated within the last update call

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 2s  . c o  m*/
}

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());/*from  w  ww .j  ava  2s.  co  m*/
    String id = run.getGeneratedKeys();
    topic.setId(id);
}