mysql的ps.setmaxrows_Java PreparedStatement.setMaxRows方法代碼示例

本文整理匯總了Java中java.sql.PreparedStatement.setMaxRows方法的典型用法代碼示例。如果您正苦於以下問題:Java PreparedStatement.setMaxRows方法的具體用法?Java PreparedStatement.setMaxRows怎麽用?Java PreparedStatement.setMaxRows使用的例子?那麽恭喜您, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.sql.PreparedStatement的用法示例。

在下文中一共展示了PreparedStatement.setMaxRows方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於我們的係統推薦出更棒的Java代碼示例。

示例1: closeQueryStatement

​點讚 3

import java.sql.PreparedStatement; //導入方法依賴的package包/類

private void closeQueryStatement(PreparedStatement ps) throws SQLException {

try {

//work around a bug in all known connection pools....

if ( ps.getMaxRows()!=0 ) ps.setMaxRows(0);

if ( ps.getQueryTimeout()!=0 ) ps.setQueryTimeout(0);

}

catch (Exception e) {

log.warn("exception clearing maxRows/queryTimeout", e);

ps.close(); //just close it; do NOT try to return it to the pool!

return; //NOTE: early exit!

}

closeStatement(ps);

if ( lastQuery==ps ) lastQuery = null;

}

開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:18,

示例2: testSetMaxRows

​點讚 2

import java.sql.PreparedStatement; //導入方法依賴的package包/類

@Test

public void testSetMaxRows() throws SQLException {

// Add 10 rows

PreparedStatement ins = conn.prepareCall("{call InsertOrders(?, ?, ?, ?, ?, ?, ?, ?)}");

for (int i = 0; i < 10; i++) {

ins.setLong(1, i);

ins.setLong(2, i);

ins.setLong(3, i);

ins.setLong(4, i);

ins.setLong(5, i);

ins.setLong(6, i);

ins.setLong(7, i);

ins.setLong(8, i);

ins.execute();

}

// check for our 10 rows

PreparedStatement cs = conn.prepareCall("{call SelectOrders}");

ResultSet rs = cs.executeQuery();

int count = 0;

while (rs.next()) {

count++;

}

assertEquals(10, count);

// constrain to 5 and try again.

cs.setMaxRows(5);

assertEquals(5, cs.getMaxRows());

rs = cs.executeQuery();

count = 0;

while (rs.next()) {

count++;

}

assertEquals(5, count);

// Verify 0 gets us everything again

cs.setMaxRows(0);

assertEquals(0, cs.getMaxRows());

rs = cs.executeQuery();

count = 0;

while (rs.next()) {

count++;

}

assertEquals(10, count);

// Go for spot-on

cs.setMaxRows(10);

assertEquals(10, cs.getMaxRows());

rs = cs.executeQuery();

count = 0;

while (rs.next()) {

count++;

}

assertEquals(10, count);

}

開發者ID:s-store,項目名稱:sstore-soft,代碼行數:56,

示例3: testBug71396PrepStatementCheck

​點讚 2

import java.sql.PreparedStatement; //導入方法依賴的package包/類

/**

* Executes one query using a newly created PreparedStatement, setting its maxRows limit, and tests if the results

* count is the expected.

*/

private void testBug71396PrepStatementCheck(Connection testConn, String query, int expRowCount, int maxRows) throws SQLException {

PreparedStatement chkPStmt;

chkPStmt = testConn.prepareStatement(query);

if (maxRows > 0) {

chkPStmt.setMaxRows(maxRows);

}

testBug71396PrepStatementCheck(chkPStmt, query, expRowCount);

chkPStmt.close();

}

開發者ID:bragex,項目名稱:the-vigilantes,代碼行數:15,

示例4: selectTriggerToAcquire

​點讚 2

import java.sql.PreparedStatement; //導入方法依賴的package包/類

/**

*

* Select the next trigger which will fire to fire between the two given timestamps

* in ascending order of fire time, and then descending by priority.

*

*

* @param conn

* the DB Connection

* @param noLaterThan

* highest value of getNextFireTime() of the triggers (exclusive)

* @param noEarlierThan

* highest value of getNextFireTime() of the triggers (inclusive)

* @param maxCount

* maximum number of trigger keys allow to acquired in the returning list.

*

* @return A (never null, possibly empty) list of the identifiers (Key objects) of the next triggers to be fired.

*/

public List selectTriggerToAcquire(Connection conn, long noLaterThan, long noEarlierThan, int maxCount)

throws SQLException {

PreparedStatement ps = null;

ResultSet rs = null;

List nextTriggers = new LinkedList();

try {

ps = conn.prepareStatement(rtp(SELECT_NEXT_TRIGGER_TO_ACQUIRE));

// Set max rows to retrieve

if (maxCount < 1)

maxCount = 1; // we want at least one trigger back.

ps.setMaxRows(maxCount);

// Try to give jdbc driver a hint to hopefully not pull over more than the few rows we actually need.

// Note: in some jdbc drivers, such as MySQL, you must set maxRows before fetchSize, or you get exception!

ps.setFetchSize(maxCount);

ps.setString(1, STATE_WAITING);

ps.setBigDecimal(2, new BigDecimal(String.valueOf(noLaterThan)));

ps.setBigDecimal(3, new BigDecimal(String.valueOf(noEarlierThan)));

rs = ps.executeQuery();

while (rs.next() && nextTriggers.size() <= maxCount) {

nextTriggers.add(triggerKey(

rs.getString(COL_TRIGGER_NAME),

rs.getString(COL_TRIGGER_GROUP)));

}

return nextTriggers;

} finally {

closeResultSet(rs);

closeStatement(ps);

}

}

開發者ID:lamsfoundation,項目名稱:lams,代碼行數:52,

示例5: selectTriggerToAcquire

​點讚 2

import java.sql.PreparedStatement; //導入方法依賴的package包/類

/**

*

* Select the next trigger which will fire to fire between the two given timestamps

* in ascending order of fire time, and then descending by priority.

*

*

* @param conn

* the DB Connection

* @param noLaterThan

* highest value of getNextFireTime() of the triggers (exclusive)

* @param noEarlierThan

* highest value of getNextFireTime() of the triggers (inclusive)

*

* @return A (never null, possibly empty) list of the identifiers (Key objects) of the next triggers to be fired.

*/

public List selectTriggerToAcquire(Connection conn, long noLaterThan, long noEarlierThan)

throws SQLException {

PreparedStatement ps = null;

ResultSet rs = null;

List nextTriggers = new LinkedList();

try {

ps = conn.prepareStatement(rtp(SELECT_NEXT_TRIGGER_TO_ACQUIRE));

// Try to give jdbc driver a hint to hopefully not pull over

// more than the few rows we actually need.

ps.setFetchSize(5);

ps.setMaxRows(5);

ps.setString(1, STATE_WAITING);

ps.setBigDecimal(2, new BigDecimal(String.valueOf(noLaterThan)));

ps.setBigDecimal(3, new BigDecimal(String.valueOf(noEarlierThan)));

rs = ps.executeQuery();

while (rs.next() && nextTriggers.size() < 5) {

nextTriggers.add(new Key(

rs.getString(COL_TRIGGER_NAME),

rs.getString(COL_TRIGGER_GROUP)));

}

return nextTriggers;

} finally {

closeResultSet(rs);

closeStatement(ps);

}

}

開發者ID:AsuraTeam,項目名稱:asura,代碼行數:46,

示例6: checkStatementExecute

​點讚 2

import java.sql.PreparedStatement; //導入方法依賴的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();

}

開發者ID:apache,項目名稱:calcite-avatica,代碼行數:37,

示例7: createLocationsStatement

​點讚 2

import java.sql.PreparedStatement; //導入方法依賴的package包/類

private PreparedStatement createLocationsStatement(LocationsRequest request, Connection conn, QueryColumnsInfo queryInfo) throws Exception

{

Geometry geom = request.getGeometry();

Envelope bbox = request.getBBox();

byte[] geomBytes = geometryToWKB(geom, bbox);

// at the end, we add virtual column to store the exact distance.

String query = "SELECT " + queryInfo.getQuery1Columns() + " FROM " + _tableName;

String whereCondition = "";

String searchCondition = buildSearchFilter(request.getSearchFilter());

if (!Helper.isEmpty(searchCondition))

whereCondition += searchCondition;

String stateText = String.format("SELECT %s FROM ORS_FindLocations('(%s) as tmp', '%s', ?, %.3f, %d) AS %s", queryInfo.getQuery2Columns(), query, whereCondition, request.getRadius(), request.getLimit(), queryInfo.getReturnTable());

if (request.getSortType() != LocationsResultSortType.NONE)

{

if (request.getSortType() == LocationsResultSortType.CATEGORY)

stateText += " ORDER BY category";

else if (request.getSortType() == LocationsResultSortType.DISTANCE)

stateText += " ORDER BY distance";

}

PreparedStatement statement = conn.prepareStatement(stateText);

statement.setMaxRows(request.getLimit());

if (geomBytes != null)

statement.setBytes(1, geomBytes);

return statement;

}

開發者ID:GIScience,項目名稱:openrouteservice,代碼行數:34,

示例8: testBug36478

​點讚 2

import java.sql.PreparedStatement; //導入方法依賴的package包/類

public void testBug36478() throws Exception {

createTable("testBug36478", "(`limit` varchar(255) not null primary key, id_limit INT, limit1 INT, maxlimit2 INT)");

this.stmt.execute("INSERT INTO testBug36478 VALUES ('bahblah',1,1,1)");

this.stmt.execute("INSERT INTO testBug36478 VALUES ('bahblah2',2,2,2)");

this.pstmt = this.conn.prepareStatement("select 1 FROM testBug36478");

this.pstmt.setMaxRows(1);

this.rs = this.pstmt.executeQuery();

this.rs.first();

assertTrue(this.rs.isFirst());

assertTrue(this.rs.isLast());

this.pstmt = this.conn.prepareStatement("select `limit`, id_limit, limit1, maxlimit2 FROM testBug36478");

this.pstmt.setMaxRows(0);

this.rs = this.pstmt.executeQuery();

this.rs.first();

assertTrue(this.rs.isFirst());

assertFalse(this.rs.isLast());

//SSPS

Connection _conn = null;

PreparedStatement s = null;

try {

Properties props = new Properties();

props.setProperty("useServerPrepStmts", "true");

_conn = getConnectionWithProps(props);

s = _conn.prepareStatement("select 1 FROM testBug36478");

s.setMaxRows(1);

ResultSet _rs = s.executeQuery();

_rs.first();

assertTrue(_rs.isFirst());

assertTrue(_rs.isLast());

s = _conn.prepareStatement("select `limit`, id_limit, limit1, maxlimit2 FROM testBug36478");

s.setMaxRows(0);

_rs = s.executeQuery();

_rs.first();

assertTrue(_rs.isFirst());

assertFalse(_rs.isLast());

} finally {

if (s != null) {

s.close();

}

if (_conn != null) {

_conn.close();

}

}

}

開發者ID:bragex,項目名稱:the-vigilantes,代碼行數:55,

示例9: setMaxRows

​點讚 2

import java.sql.PreparedStatement; //導入方法依賴的package包/類

@Override

public void setMaxRows(PreparedStatement statement) throws SQLException {

if ( LimitHelper.hasMaxRows( selection ) ) {

statement.setMaxRows( selection.getMaxRows() + convertToFirstRowValue( LimitHelper.getFirstRow( selection ) ) );

}

}

開發者ID:lamsfoundation,項目名稱:lams,代碼行數:7,

示例10: setMaxRows

​點讚 2

import java.sql.PreparedStatement; //導入方法依賴的package包/類

/**

* Use JDBC API to limit the number of rows returned by the SQL query if necessary

*/

private void setMaxRows(final PreparedStatement st, final RowSelection selection) throws SQLException {

if ( hasMaxRows(selection) ) {

st.setMaxRows( selection.getMaxRows().intValue() + getFirstRow(selection) );

}

}

開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:9,

示例11: writeData

​點讚 2

import java.sql.PreparedStatement; //導入方法依賴的package包/類

public void writeData(String destTableName, Connection destConn)

throws SQLException {

PreparedStatement pstmt = null;

ResultSet rs = null;

try {

// To download the entire result set it is supposedly much

// faster to do forward only. This means that we can only

// call rs.next() and not rs.first(). So we must make sure

// that rs.next() is not called before we start downloading

// the table. This is called in populateTable.

pstmt = sourceConn.prepareStatement(sql,

ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);

log.log(XLevel.DEBUG2, "Querying data...");

pstmt.setFetchSize(10000);

pstmt.setMaxRows(0);

stat.startInitialFetch();

rs = pstmt.executeQuery();

// If no data was found quit.

if (rs == null) {

log.warn("No data found in using sql statement:" + sql);

return;

}

stat.completeInitialFetch();

log.log(XLevel.DEBUG2, "Processing data...");

log.log(XLevel.DEBUG2, "Populating table with data...");

populateTable(destTableName, rs, destConn);

} finally {

try {

if (rs != null)

rs.close();

if (pstmt != null)

pstmt.close();

} catch (SQLException ignored) {

}

}

stat.done();

}

開發者ID:applitect,項目名稱:DbShadow,代碼行數:44,

示例12: getMeta

​點讚 2

import java.sql.PreparedStatement; //導入方法依賴的package包/類

/**

* Creates a new {@link MetaData} object for a given sql query.

* At this time only one table in the from clause can be specified

* due to a Oracle inefficiency in their JDBC driver meta data fetch.

* @param sql

* @param sourceConn

* @return

* @throws SQLException

* @throws IOException

*/

public static MetaData getMeta(String sql, Connection sourceConn)

throws SQLException, IOException {

PreparedStatement pstmt = null;

ResultSet rs = null;

try {

// To download the entire result set it is supposedly much

// faster to do forward only. This means that we can only

// call rs.next() and not rs.first(). So we must make sure

// that rs.next() is not called before we start downloading

// the table. This is called in populateTable.

pstmt = sourceConn.prepareStatement(sql,

ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);

pstmt.setFetchSize(1);

pstmt.setMaxRows(1);

rs = pstmt.executeQuery();

// If no data was found quit.

if (rs == null) {

log.warn("No data found in using sql statement:" + sql);

return null;

}

log.log(XLevel.DEBUG2, "Processing data...");

// Get the table's metadata

ResultSetMetaData meta = rs.getMetaData();

// For the result metadata set, we need to cache the count and

// column names. Calls to getXXX for meta data can make calls

// back to the database. We're pretty sure they're not going to

// change while were running.

int cols = meta.getColumnCount() + 1;

ArrayList sourceCols = new ArrayList();

for (int i = 1; i < cols; i++)

sourceCols.add(meta.getColumnName(i));

// XXX Oracle 10 Sucks!

// Oracle does not implement the getTableName and getSchemaName

// methods. Since they do not implement them, we have to parse

// the query to determine the table name.

String tableName = meta.getTableName(1);

if (tableName.trim().length() == 0) {

Pattern p = Pattern.compile(".*\\s+from\\s+\\w*?\\.?(\\w+).*",

Pattern.CASE_INSENSITIVE);

Matcher m = p.matcher(sql);

if (m.matches())

tableName = m.group(1).toUpperCase();

}

MetaData metaData = new MetaData(tableName, meta, sourceConn.getMetaData());

return metaData;

} finally {

try {

if (rs != null)

rs.close();

if (pstmt != null)

pstmt.close();

} catch (SQLException ignored) {

}

}

}

開發者ID:applitect,項目名稱:DbShadow,代碼行數:73,

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值