commons dbutils 常用方法要运行要使用了dbcp连接池 from (select id, name,alias, op_seq, op_status fr
commons dbutils 常用方法
要运行要使用了dbcp连接池
" from (select id, name, alias, op_seq, op_status from user" +
" where op_status = 0" +
" order by op_seq) where rownum <= ?";
// Connection conn = null;
QueryLoader q = QueryLoader.instance();
Object params = 10;
List<RefObject> list = null;
List<Map<String, Object>> iMap = null;
List<Object[]> arrResult = null;
try
{
//查询返回数组列表
arrResult = (List<Object[]>)qr.query(conn,sql, arrayResult, params);
//查询返回JavaBean列表
list = qr.query(conn,sql, rList, params);
//查询返回Map列表
iMap = qr.query(conn,sql, map, params);
// qr.fillStatementWithBean(arg0, arg1, arg2);
// DbUtils.
conn.setAutoCommit(false);
/** 此段代码是通过查询得到的数组直接批量插入到数据,简洁高效
Object[][] inParam = new Object[arrResult.size()][];
for (int i = 0; i < inParam.length; i++)
{
inParam[i] = arrResult.get(i);
}
qr.batch(conn,TransConst.USER_INSERT_SQL, inParam);
*/
PreparedStatement stmt = conn.prepareStatement(TransConst.USER_INSERT_SQL);
String[] props = new String[] {"id", "name", "alias"};
for (RefObject user : list)
{
//通过JavaBean方式填充Statement参数
qr.fillStatementWithBean(stmt, user, props);
stmt.addBatch();
}
stmt.executeBatch();