/** * Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the * query, mapping each row to a Java object via a RowMapper. * * @param sql * @param args * @param sqlTypes * @param rowMapper * @return * @throws SQLException */ public List query(final String sql, Object[] args, int[] sqlTypes, RowMapper rowMapper) { if (showSql) { logger.info(getFinalSql(sql, args, sqlTypes)); } Connection conn = null; PreparedStatement pstmt = null; ResultSet rs = null; try { conn = getConnection(); pstmt = conn.prepareStatement(sql); if (args != null) { if (sqlTypes == null) { JdbcUtils.setPreparedStatementValue(pstmt, args); } else { JdbcUtils.setPreparedStatementValue(pstmt, args, sqlTypes); } } applyQueryTimeOut(pstmt); rs = pstmt.executeQuery(); if (rs == null) { return null; } else { List resultList = new ArrayList(); while (rs.next()) { resultList.add(rowMapper.mapRow(rs, rs.getRow())); } return resultList; } } catch (SQLException e) { throw new RuntimeException(e); } finally { JdbcUtils.closeQuietly(conn, pstmt, rs); } }