Apache Common DBUtil 클래스를 사용함으로써, 그동안 삽질했던 DB 관련 Bean 세팅 노가다에서
벗어 날수 있다. 적용 해야지 하면서 미루다가 정리해서 포스팅.
다운로드 : http://commons.apache.org/downloads/download_dbutils.cgi
API : http://commons.apache.org/dbutils/apidocs/index.html
Single Result
...........
QueryRunner runner = new QueryRunner();
ResultSetHandler rsh = new BeanHandler(TestBean.class);
TestBean bean = null;
try {
query.append("select * from TEST");
bean = (TestBean) runner.query(conn, query.toString(), role_code, rsh);
...........
Multi Result
...........
TestBean bean = null;
RowProcessor convert = BasicRowProcessor.instance();
ArrayList list = new ArrayList();
try {
query.append("select * from TEST");
pstmt = conn.prepareStatement( query.toString() );
rs = pstmt.executeQuery();
list = (ArrayList) convert.toBeanList(rs, TestBean.class);
........
Update( insert, update 같음 )
QueryRunner runner = new QueryRunner();
try {
conn.setAutoCommit(false);
query.append("update TEST set user_name=?, user_nick=? where role_code=?");
Object[] param = {
"조태수",
"taesuz"
};
iResult = runner.update(conn, query.toString(), param);
conn.commit();
댓글 없음:
댓글 쓰기