當前位置: 首頁>>代碼示例>>Java>>正文


Java ResultSetHandler.handle方法代碼示例

本文整理匯總了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);
    }
}
 
開發者ID:goldmansachs,項目名稱:obevo,代碼行數:18,代碼來源:JdbcHelper.java

示例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());
}
 
開發者ID:apache,項目名稱:commons-dbutils,代碼行數:27,代碼來源:MapListHandlerTest.java

示例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"));
}
 
開發者ID:apache,項目名稱:commons-dbutils,代碼行數:22,代碼來源:KeyedHandlerTest.java

示例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());
}
 
開發者ID:apache,項目名稱:commons-dbutils,代碼行數:27,代碼來源:BeanListHandlerTest.java

示例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());
}
 
開發者ID:apache,項目名稱:commons-dbutils,代碼行數:27,代碼來源:ArrayListHandlerTest.java

示例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);
    }
}
 
開發者ID:zoowii,項目名稱:jpa-utils,代碼行數:16,代碼來源:JdbcQuery.java

示例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);
    }
}
 
開發者ID:zoowii,項目名稱:jpa-utils,代碼行數:15,代碼來源:JdbcQuery.java

示例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]);
}
 
開發者ID:apache,項目名稱:commons-dbutils,代碼行數:11,代碼來源:ArrayHandlerTest.java

示例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());
}
 
開發者ID:apache,項目名稱:commons-dbutils,代碼行數:8,代碼來源:ArrayListHandlerTest.java

示例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());
}
 
開發者ID:apache,項目名稱:commons-dbutils,代碼行數:11,代碼來源:BeanHandlerTest.java

示例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());
}
 
開發者ID:apache,項目名稱:commons-dbutils,代碼行數:11,代碼來源:BeanHandlerTest.java

示例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"));
}
 
開發者ID:apache,項目名稱:commons-dbutils,代碼行數:11,代碼來源:MapHandlerTest.java

示例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));
}
 
開發者ID:apache,項目名稱:commons-dbutils,代碼行數:11,代碼來源:ColumnListHandlerTest.java

示例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));
}
 
開發者ID:apache,項目名稱:commons-dbutils,代碼行數:11,代碼來源:ColumnListHandlerTest.java

示例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());
}
 
開發者ID:apache,項目名稱:commons-dbutils,代碼行數:8,代碼來源:ColumnListHandlerTest.java


注:本文中的org.apache.commons.dbutils.ResultSetHandler.handle方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。