本文整理汇总了Java中java.sql.Statement.setMaxRows方法的典型用法代码示例。如果您正苦于以下问题:Java Statement.setMaxRows方法的具体用法?Java Statement.setMaxRows怎么用?Java Statement.setMaxRows使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.sql.Statement
的用法示例。
在下文中一共展示了Statement.setMaxRows方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testBug71396MultiSettingsCheck
import java.sql.Statement; //导入方法依赖的package包/类
/**
* Executes a query containing the clause LIMIT with a Statement and a PreparedStatement, using a combination of
* Connection properties, maxRows value and limit clause value, and tests if the results count is the expected.
*/
private void testBug71396MultiSettingsCheck(String connProps, int maxRows, int limitClause, int expRowCount) throws SQLException {
Connection testConn = getConnectionWithProps(connProps);
Statement testStmt = testConn.createStatement();
if (maxRows > 0) {
testStmt.setMaxRows(maxRows);
}
testStmt.execute("SELECT 1"); // force limit to be applied into current session
testBug71396StatementCheck(testStmt, String.format("SELECT * FROM testBug71396 LIMIT %d", limitClause), expRowCount);
testBug71396PrepStatementCheck(testConn, String.format("SELECT * FROM testBug71396 LIMIT %d", limitClause), expRowCount, maxRows);
testStmt.close();
testConn.close();
}
示例2: testSetMaxRows
import java.sql.Statement; //导入方法依赖的package包/类
/**
* Tests fix for BUG#907
*
* @throws Exception
* if an error occurs
*/
public void testSetMaxRows() throws Exception {
Statement maxRowsStmt = null;
try {
maxRowsStmt = this.conn.createStatement();
maxRowsStmt.setMaxRows(1);
this.rs = maxRowsStmt.executeQuery("SELECT 1");
} finally {
if (maxRowsStmt != null) {
maxRowsStmt.close();
}
}
}
示例3: testBug71396StatementInit
import java.sql.Statement; //导入方法依赖的package包/类
/**
* Initializes and returns a Statement with maxRows defined. Tests the SQL_SELECT_LIMIT defined. Executing this
* query also forces this limit to be defined at session level.
*/
private Statement testBug71396StatementInit(Connection testConn, int maxRows) throws SQLException {
ResultSet testRS;
Statement testStmt = testConn.createStatement();
testStmt.setMaxRows(maxRows);
// while consulting SQL_SELECT_LIMIT setting also forces limit to be applied into current session
testRS = testStmt.executeQuery("SELECT @@SESSION.SQL_SELECT_LIMIT");
testRS.next();
assertEquals("Wrong @@SESSION.SQL_SELECT_LIMIT", maxRows, testRS.getInt(1));
return testStmt;
}
示例4: setMaxRowsToReturn
import java.sql.Statement; //导入方法依赖的package包/类
/**
* Set the maximum rows to return to the client side
*
* @param statement
* the statement to set
* @param databaseConfigurator
* the DatabaseConfigurator which contains the getMaxRowsToReturn()
* method
* @throws SQLException
*/
public static void setMaxRowsToReturn(Statement statement,
DatabaseConfigurator databaseConfigurator) throws SQLException, IOException {
int maxRowsToReturn = DatabaseConfiguratorCall
.getMaxRowsToReturn(databaseConfigurator);
if (maxRowsToReturn > 0) {
if (statement.getMaxRows() == 0
|| (statement.getMaxRows() > maxRowsToReturn)) {
statement.setFetchSize(0); // To avoid any possible conflict
statement.setMaxRows(maxRowsToReturn);
}
}
}
示例5: applyStatementSettings
import java.sql.Statement; //导入方法依赖的package包/类
/**
* Prepare the given JDBC Statement (or PreparedStatement or CallableStatement),
* applying statement settings such as fetch size, max rows, and query timeout.
* @param stmt the JDBC Statement to prepare
* @throws SQLException if thrown by JDBC API
* @see #setFetchSize
* @see #setMaxRows
* @see #setQueryTimeout
* @see org.springframework.jdbc.datasource.DataSourceUtils#applyTransactionTimeout
*/
protected void applyStatementSettings(Statement stmt) throws SQLException {
int fetchSize = getFetchSize();
if (fetchSize > 0) {
stmt.setFetchSize(fetchSize);
}
int maxRows = getMaxRows();
if (maxRows > 0) {
stmt.setMaxRows(maxRows);
}
DataSourceUtils.applyTimeout(stmt, getDataSource(), getQueryTimeout());
}
示例6: setMaxRows
import java.sql.Statement; //导入方法依赖的package包/类
/**
* Sets the provided maximum number of rows on the given statement.
*
* @param statement The JDBC Statement to operate on
* @param maxRowCount The maximum number of rows which should be returned for the query
*/
void setMaxRows(Statement statement, long maxRowCount) throws SQLException {
// Special handling of maxRowCount as JDBC 0 is unlimited, our meta 0 row
if (maxRowCount > 0) {
AvaticaUtils.setLargeMaxRows(statement, maxRowCount);
} else if (maxRowCount < 0) {
statement.setMaxRows(0);
}
}
示例7: checkStatementExecute
import java.sql.Statement; //导入方法依赖的package包/类
private void checkStatementExecute(Connection connection,
boolean prepare, int maxRowCount) throws SQLException {
final String sql = "select * from (\n"
+ " values (1, 'a'), (null, 'b'), (3, 'c')) as t (c1, c2)";
final Statement statement;
final ResultSet resultSet;
final ParameterMetaData parameterMetaData;
if (prepare) {
final PreparedStatement ps = connection.prepareStatement(sql);
statement = ps;
ps.setMaxRows(maxRowCount);
parameterMetaData = ps.getParameterMetaData();
assertTrue(ps.execute());
resultSet = ps.getResultSet();
} else {
statement = connection.createStatement();
statement.setMaxRows(maxRowCount);
parameterMetaData = null;
assertTrue(statement.execute(sql));
resultSet = statement.getResultSet();
}
if (parameterMetaData != null) {
assertThat(parameterMetaData.getParameterCount(), equalTo(0));
}
final ResultSetMetaData metaData = resultSet.getMetaData();
assertEquals(2, metaData.getColumnCount());
assertEquals("C1", metaData.getColumnName(1));
assertEquals("C2", metaData.getColumnName(2));
for (int i = 0; i < maxRowCount || (maxRowCount == 0 && i < 3); i++) {
assertTrue(resultSet.next());
}
assertFalse(resultSet.next());
resultSet.close();
statement.close();
connection.close();
}
示例8: prepareSQLStatement
import java.sql.Statement; //导入方法依赖的package包/类
private Statement prepareSQLStatement(Connection conn, String sql) throws SQLException {
Statement stmt;
if (sql.startsWith("{")) { // NOI18N
stmt = useScrollableCursors
? conn.prepareCall(sql, resultSetScrollType, ResultSet.CONCUR_READ_ONLY)
: conn.prepareCall(sql);
} else if (isSelectStatement(sql)) {
stmt = useScrollableCursors
? conn.createStatement(resultSetScrollType, ResultSet.CONCUR_READ_ONLY)
: conn.createStatement();
// set a reasonable fetchsize
setFetchSize(stmt, 50);
// hint to only query a certain number of rows -> potentially
// improve performance for low page numbers
// only usable for "non-total" resultsets
try {
Integer maxRows = 0;
for (DataViewPageContext pageContext : dataView.getPageContexts()) {
int currentRows = pageContext.getCurrentPos();
int pageSize = pageContext.getPageSize();
if (pageSize <= 0) {
maxRows = 0;
break;
} else {
maxRows = Math.max(maxRows, currentRows + pageSize);
}
}
stmt.setMaxRows(maxRows);
} catch (SQLException exc) {
LOGGER.log(Level.WARNING, "Unable to set Max row count", exc); // NOI18N
try {
stmt.setMaxRows(0);
} catch (SQLException ex) {}
}
} else {
stmt = useScrollableCursors
? conn.createStatement(resultSetScrollType, ResultSet.CONCUR_READ_ONLY)
: conn.createStatement();
}
return stmt;
}