本文整理匯總了Java中org.apache.commons.dbutils.ResultSetHandler.handle方法的典型用法代碼示例。如果您正苦於以下問題:Java ResultSetHandler.handle方法的具體用法?Java ResultSetHandler.handle怎麽用?Java ResultSetHandler.handle使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.dbutils.ResultSetHandler
的用法示例。
在下文中一共展示了ResultSetHandler.handle方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: query
import org.apache.commons.dbutils.ResultSetHandler; //導入方法依賴的package包/類
public <T> T query(Connection conn, String sql, ResultSetHandler<T> resultSetHandler) {
Statement statement = null;
ResultSet resultSet = null;
try {
statement = conn.createStatement();
if (LOG.isDebugEnabled()) {
LOG.debug("Executing query on {}: {}", displayConnection(conn), sql);
}
resultSet = statement.executeQuery(sql);
return resultSetHandler.handle(resultSet);
} catch (SQLException e) {
throw new DataAccessException(e);
} finally {
DbUtils.closeQuietly(resultSet);
DbUtils.closeQuietly(statement);
}
}
示例2: testHandle
import org.apache.commons.dbutils.ResultSetHandler; //導入方法依賴的package包/類
public void testHandle() throws SQLException {
ResultSetHandler<List<Map<String,Object>>> h = new MapListHandler();
List<Map<String,Object>> results = h.handle(this.rs);
assertNotNull(results);
assertEquals(ROWS, results.size());
Iterator<Map<String,Object>> iter = results.iterator();
Map<String,Object> row = null;
assertTrue(iter.hasNext());
row = iter.next();
assertEquals(COLS, row.keySet().size());
assertEquals("1", row.get("one"));
assertEquals("2", row.get("TWO"));
assertEquals("THREE", row.get("Three"));
assertTrue(iter.hasNext());
row = iter.next();
assertEquals(COLS, row.keySet().size());
assertEquals("4", row.get("one"));
assertEquals("5", row.get("TWO"));
assertEquals("SIX", row.get("Three"));
assertFalse(iter.hasNext());
}
示例3: testColumnIndexHandle
import org.apache.commons.dbutils.ResultSetHandler; //導入方法依賴的package包/類
public void testColumnIndexHandle() throws SQLException {
ResultSetHandler<Map<String,Map<String,Object>>> h = new KeyedHandler<String>(2);
Map<String,Map<String,Object>> results = h.handle(this.rs);
assertNotNull(results);
assertEquals(ROWS, results.size());
Map<String,Object> row = null;
for(Entry<String, Map<String, Object>> entry : results.entrySet())
{
Object key = entry.getKey();
assertNotNull(key);
row = entry.getValue();
assertNotNull(row);
assertEquals(COLS, row.keySet().size());
}
row = results.get("5");
assertEquals("4", row.get("one"));
assertEquals("5", row.get("TWO"));
assertEquals("SIX", row.get("Three"));
}
示例4: testHandle
import org.apache.commons.dbutils.ResultSetHandler; //導入方法依賴的package包/類
public void testHandle() throws SQLException {
ResultSetHandler<List<TestBean>> h = new BeanListHandler<TestBean>(TestBean.class);
List<TestBean> results = h.handle(this.rs);
assertNotNull(results);
assertEquals(ROWS, results.size());
Iterator<TestBean> iter = results.iterator();
TestBean row = null;
assertTrue(iter.hasNext());
row = iter.next();
assertEquals("1", row.getOne());
assertEquals("2", row.getTwo());
assertEquals(TestBean.Ordinal.THREE, row.getThree());
assertEquals("not set", row.getDoNotSet());
assertTrue(iter.hasNext());
row = iter.next();
assertEquals("4", row.getOne());
assertEquals("5", row.getTwo());
assertEquals(TestBean.Ordinal.SIX, row.getThree());
assertEquals("not set", row.getDoNotSet());
assertFalse(iter.hasNext());
}
示例5: testHandle
import org.apache.commons.dbutils.ResultSetHandler; //導入方法依賴的package包/類
public void testHandle() throws SQLException {
ResultSetHandler<List<Object[]>> h = new ArrayListHandler();
List<Object[]> results = h.handle(this.rs);
assertNotNull(results);
assertEquals(ROWS, results.size());
Iterator<Object[]> iter = results.iterator();
Object[] row = null;
assertTrue(iter.hasNext());
row = iter.next();
assertEquals(COLS, row.length);
assertEquals("1", row[0]);
assertEquals("2", row[1]);
assertEquals("THREE", row[2]);
assertTrue(iter.hasNext());
row = iter.next();
assertEquals(COLS, row.length);
assertEquals("4", row[0]);
assertEquals("5", row[1]);
assertEquals("SIX", row[2]);
assertFalse(iter.hasNext());
}
示例6: getResultList
import org.apache.commons.dbutils.ResultSetHandler; //導入方法依賴的package包/類
@Override
public List getResultList() {
try {
ResultSetHandler<List<Object>> handler = JdbcSession.getListResultSetHandler(modelMeta);
Logger.logSql("query sql: " + namedParameterStatement.getQuery());
ResultSet resultSet = namedParameterStatement.executeQuery();
try {
return handler.handle(resultSet);
} finally {
resultSet.close();
}
} catch (SQLException e) {
throw new JdbcRuntimeException(e);
}
}
示例7: getSingleResult
import org.apache.commons.dbutils.ResultSetHandler; //導入方法依賴的package包/類
@Override
public Object getSingleResult() {
try {
ResultSetHandler<Object> handler = JdbcSession.getRowBeanResultSetHandler(modelMeta);
ResultSet resultSet = namedParameterStatement.executeQuery();
try {
return handler.handle(resultSet);
} finally {
resultSet.close();
}
} catch (SQLException e) {
throw new JdbcRuntimeException(e);
}
}
示例8: testHandle
import org.apache.commons.dbutils.ResultSetHandler; //導入方法依賴的package包/類
public void testHandle() throws SQLException {
ResultSetHandler<Object[]> h = new ArrayHandler();
Object[] results = h.handle(this.rs);
assertNotNull(results);
assertEquals(COLS, results.length);
assertEquals("1", results[0]);
assertEquals("2", results[1]);
assertEquals("THREE", results[2]);
}
示例9: testEmptyResultSetHandle
import org.apache.commons.dbutils.ResultSetHandler; //導入方法依賴的package包/類
public void testEmptyResultSetHandle() throws SQLException {
ResultSetHandler<List<Object[]>> h = new ArrayListHandler();
List<Object[]> results = h.handle(this.emptyResultSet);
assertNotNull(results);
assertTrue(results.isEmpty());
}
示例10: testHandleToSuperClass
import org.apache.commons.dbutils.ResultSetHandler; //導入方法依賴的package包/類
public void testHandleToSuperClass() throws SQLException {
ResultSetHandler<TestBean> h = new BeanHandler<TestBean>(SubTestBean.class);
TestBean results = h.handle(this.rs);
assertNotNull(results);
assertEquals("1", results.getOne());
assertEquals("2", results.getTwo());
assertEquals(TestBean.Ordinal.THREE, results.getThree());
assertEquals("not set", results.getDoNotSet());
}
示例11: testHandle
import org.apache.commons.dbutils.ResultSetHandler; //導入方法依賴的package包/類
public void testHandle() throws SQLException {
ResultSetHandler<TestBean> h = new BeanHandler<TestBean>(TestBean.class);
TestBean results = h.handle(this.rs);
assertNotNull(results);
assertEquals("1", results.getOne());
assertEquals("2", results.getTwo());
assertEquals(TestBean.Ordinal.THREE, results.getThree());
assertEquals("not set", results.getDoNotSet());
}
示例12: testHandle
import org.apache.commons.dbutils.ResultSetHandler; //導入方法依賴的package包/類
public void testHandle() throws SQLException {
ResultSetHandler<Map<String,Object>> h = new MapHandler();
Map<String,Object> results = h.handle(this.rs);
assertNotNull(results);
assertEquals(COLS, results.keySet().size());
assertEquals("1", results.get("ONE"));
assertEquals("2", results.get("two"));
assertEquals("THREE", results.get("Three"));
}
示例13: testColumnIndexHandle
import org.apache.commons.dbutils.ResultSetHandler; //導入方法依賴的package包/類
public void testColumnIndexHandle() throws SQLException {
ResultSetHandler<List<String>> h = new ColumnListHandler<String>(2);
List<String> results = h.handle(this.rs);
assertNotNull(results);
assertEquals(ROWS, results.size());
assertEquals("2", results.get(0));
assertEquals("5", results.get(1));
}
示例14: testColumnNameHandle
import org.apache.commons.dbutils.ResultSetHandler; //導入方法依賴的package包/類
public void testColumnNameHandle() throws SQLException {
ResultSetHandler<List<Integer>> h = new ColumnListHandler<Integer>("intTest");
List<Integer> results = h.handle(this.rs);
assertNotNull(results);
assertEquals(ROWS, results.size());
assertEquals(new Integer(1), results.get(0));
assertEquals(new Integer(3), results.get(1));
}
示例15: testEmptyResultSetHandle
import org.apache.commons.dbutils.ResultSetHandler; //導入方法依賴的package包/類
public void testEmptyResultSetHandle() throws SQLException {
ResultSetHandler<List<String>> h = new ColumnListHandler<String>();
List<String> results = h.handle(this.emptyResultSet);
assertNotNull(results);
assertTrue(results.isEmpty());
}