weblog

技術的なメモ置き場。

DBUtilsを使う

Apache Commons DBUtilsの使い方メモ
DBUtils1.5
http://commons.apache.org/dbutils/index.html

・抽出
QueryRunner qr = new QueryRunner();
ResultSetHandler> rsh = new BeanListHandler(T.class);
List list = qr.query(Connection, "SELECT * FROM HOGE;", rsh);

・挿入
QueryRunner qr = new QueryRunner();
qr.update(Connection, "INSERT INTO HOGE (foo, bar) VALUES (?, ?);", hoge1, hoge2);

・更新
QueryRunner qr = new QueryRunner();
qr.update(Connection, "UPDATE HOGE SET foo = ? WHERE bar = ?;", hoge1, hoge2);

・削除
QueryRunner qr = new QueryRunner();
qr.update(Connection, "DELETE FROM HOGE WHERE foo = ?;", hoge1);