下面列出了java.sql.PreparedStatement#getFetchSize ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public List<Map<String, Object>> selectAllMap(Connection connection, String sql, List<Object> args, MappingVo resultMap, Integer fetchSize)
throws SQLException {
PreparedStatement ps = connection.prepareStatement(sql);
try {
setParameters(ps, args);
if (null != fetchSize && fetchSize.intValue() != ps.getFetchSize()) {
ps.setFetchSize(fetchSize.intValue());
}
ResultSet rs = ps.executeQuery();
return getResults(rs, resultMap);
} finally {
try {
ps.close();
} catch (SQLException e) {
// ignore
}
}
}
public List<XCO> selectAllXCO(Connection connection, String sql, List<Object> args, MappingVo resultMap, Integer fetchSize) throws SQLException {
PreparedStatement ps = connection.prepareStatement(sql);
try {
setParameters(ps, args);
if (null != fetchSize && fetchSize.intValue() != ps.getFetchSize()) {
ps.setFetchSize(fetchSize.intValue());
}
ResultSet rs = ps.executeQuery();
return getXCOResults(rs, resultMap);
} finally {
try {
ps.close();
} catch (SQLException e) {
// ignore
}
}
}
@Test
public void testPreparedStatementConfig() throws SQLException {
PreparedStatement preparedStatement = swConnection.prepareStatement("INSERT INTO test VALUES( ? , ?)", 1);
preparedStatement.setInt(1, 1);
preparedStatement.setString(2, "a");
preparedStatement.getUpdateCount();
preparedStatement.setFetchDirection(1);
preparedStatement.getFetchDirection();
preparedStatement.getResultSetConcurrency();
preparedStatement.getResultSetType();
preparedStatement.isClosed();
preparedStatement.setPoolable(false);
preparedStatement.isPoolable();
preparedStatement.getWarnings();
preparedStatement.clearWarnings();
preparedStatement.setCursorName("test");
preparedStatement.setMaxFieldSize(11);
preparedStatement.getMaxFieldSize();
preparedStatement.setMaxRows(10);
preparedStatement.getMaxRows();
preparedStatement.getParameterMetaData();
preparedStatement.setEscapeProcessing(true);
preparedStatement.setFetchSize(1);
preparedStatement.getFetchSize();
preparedStatement.setQueryTimeout(1);
preparedStatement.getQueryTimeout();
Connection connection = preparedStatement.getConnection();
preparedStatement.execute();
preparedStatement.getMoreResults();
preparedStatement.getMoreResults(1);
preparedStatement.getResultSetHoldability();
preparedStatement.getMetaData();
preparedStatement.getResultSet();
preparedStatement.close();
verify(mysqlPreparedStatement).getUpdateCount();
verify(mysqlPreparedStatement).getMoreResults();
verify(mysqlPreparedStatement).setFetchDirection(anyInt());
verify(mysqlPreparedStatement).getFetchDirection();
verify(mysqlPreparedStatement).getResultSetType();
verify(mysqlPreparedStatement).isClosed();
verify(mysqlPreparedStatement).setPoolable(anyBoolean());
verify(mysqlPreparedStatement).getWarnings();
verify(mysqlPreparedStatement).clearWarnings();
verify(mysqlPreparedStatement).setCursorName(anyString());
verify(mysqlPreparedStatement).setMaxFieldSize(anyInt());
verify(mysqlPreparedStatement).getMaxFieldSize();
verify(mysqlPreparedStatement).setMaxRows(anyInt());
verify(mysqlPreparedStatement).getMaxRows();
verify(mysqlPreparedStatement).setEscapeProcessing(anyBoolean());
verify(mysqlPreparedStatement).getResultSetConcurrency();
verify(mysqlPreparedStatement).getResultSetConcurrency();
verify(mysqlPreparedStatement).getResultSetType();
verify(mysqlPreparedStatement).getMetaData();
verify(mysqlPreparedStatement).getParameterMetaData();
verify(mysqlPreparedStatement).getMoreResults(anyInt());
verify(mysqlPreparedStatement).setFetchSize(anyInt());
verify(mysqlPreparedStatement).getFetchSize();
verify(mysqlPreparedStatement).getQueryTimeout();
verify(mysqlPreparedStatement).setQueryTimeout(anyInt());
verify(mysqlPreparedStatement).getResultSet();
assertThat(connection, CoreMatchers.<Connection>is(swConnection));
}