当前位置: 首页>>代码示例>>Java>>正文


Java Statement.clearBatch方法代码示例

本文整理汇总了Java中java.sql.Statement.clearBatch方法的典型用法代码示例。如果您正苦于以下问题:Java Statement.clearBatch方法的具体用法?Java Statement.clearBatch怎么用?Java Statement.clearBatch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.sql.Statement的用法示例。


在下文中一共展示了Statement.clearBatch方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: updatePoints

import java.sql.Statement; //导入方法依赖的package包/类
@Override
	public Status updatePoints(List<TsPoint> points) {
		//timestamp->device->sensor
		long costTime=0;
//		int count=0;
		Connection connection = null;
		Statement statement = null;
		try {
			connection=getConnection();
			statement=connection.createStatement();
			if(points!=null){
				StringBuilder sc=new StringBuilder();
				for(TsPoint point:points){
					sc.append("update ");
					sc.append(ROOT_SERIES_NAME);
					sc.append(".");
					sc.append(point.getDeviceCode());
					sc.append(".");
					sc.append(point.getSensorCode());
					sc.append(" set value=");
					sc.append(point.getValue());
					sc.append(" where");
					sc.append(" time=");
					sc.append(point.getTimestamp());
					statement.addBatch(sc.toString());
					sc.setLength(0);
				}
			}
			long startTime=System.nanoTime();
			statement.executeBatch();//批量更新
			statement.clearBatch();
			long endTime=System.nanoTime();
			costTime=endTime-startTime;
		}catch(Exception e){
			return Status.FAILED(-1);
		}finally{
			closeStatement(statement);
			closeConnection(connection);
		}
		return Status.OK(costTime);
	}
 
开发者ID:dbiir,项目名称:ts-benchmark,代码行数:42,代码来源:TsfileDB.java

示例2: testBug77681

import java.sql.Statement; //导入方法依赖的package包/类
/**
 * Tests fix for BUG#77681 - rewrite replace sql like insert when rewriteBatchedStatements=true (contribution)
 * 
 * When using 'rewriteBatchedStatements=true' we rewrite several batched statements into one single query by extending its VALUES clause. Although INSERT
 * REPLACE have the same syntax, this wasn't happening for REPLACE statements.
 * 
 * This tests the number of queries actually sent to server when rewriteBatchedStatements is used and not by using a StatementInterceptor. The test is
 * repeated for server side prepared statements. Without the fix, this test fails while checking the number of expected REPLACE queries.
 */
public void testBug77681() throws Exception {
    createTable("testBug77681", "(id INT, txt VARCHAR(50), PRIMARY KEY (id))");

    Properties props = new Properties();
    props.setProperty("statementInterceptors", TestBug77681StatementInterceptor.class.getName());

    for (int tst = 0; tst < 4; tst++) {
        props.setProperty("useServerPrepStmts", Boolean.toString((tst & 0x1) != 0));
        props.setProperty("rewriteBatchedStatements", Boolean.toString((tst & 0x2) != 0));
        Connection testConn = getConnectionWithProps(props);

        PreparedStatement testPstmt = testConn.prepareStatement("INSERT INTO testBug77681 VALUES (?, ?)");
        testPstmt.setInt(1, 1);
        testPstmt.setString(2, "one");
        testPstmt.addBatch();
        testPstmt.setInt(1, 2);
        testPstmt.setString(2, "two");
        testPstmt.addBatch();
        testPstmt.setInt(1, 3);
        testPstmt.setString(2, "three");
        testPstmt.addBatch();
        testPstmt.setInt(1, 4);
        testPstmt.setString(2, "four");
        testPstmt.addBatch();
        testPstmt.setInt(1, 5);
        testPstmt.setString(2, "five");
        testPstmt.addBatch();
        testPstmt.executeBatch();
        testPstmt.close();

        testPstmt = testConn.prepareStatement("REPLACE INTO testBug77681 VALUES (?, ?)");
        testPstmt.setInt(1, 2);
        testPstmt.setString(2, "TWO");
        testPstmt.addBatch();
        testPstmt.setInt(1, 4);
        testPstmt.setString(2, "FOUR");
        testPstmt.addBatch();
        testPstmt.setInt(1, 6);
        testPstmt.setString(2, "SIX");
        testPstmt.addBatch();
        testPstmt.executeBatch();
        testPstmt.close();

        Statement testStmt = testConn.createStatement();
        testStmt.clearBatch();
        testStmt.addBatch("INSERT INTO testBug77681 VALUES (7, 'seven')");
        testStmt.addBatch("INSERT INTO testBug77681 VALUES (8, 'eight')");
        testStmt.addBatch("INSERT INTO testBug77681 VALUES (9, 'nine')");
        testStmt.addBatch("INSERT INTO testBug77681 VALUES (10, 'ten')");
        testStmt.addBatch("INSERT INTO testBug77681 VALUES (11, 'eleven')");
        testStmt.executeBatch();

        testStmt.clearBatch();
        testStmt.addBatch("REPLACE INTO testBug77681 VALUES (8, 'EIGHT')");
        testStmt.addBatch("REPLACE INTO testBug77681 VALUES (10, 'TEN')");
        testStmt.addBatch("REPLACE INTO testBug77681 VALUES (12, 'TWELVE')");
        testStmt.addBatch("REPLACE INTO testBug77681 VALUES (14, 'FOURTEEN')");
        testStmt.addBatch("REPLACE INTO testBug77681 VALUES (16, 'SIXTEEN')");
        testStmt.executeBatch();

        this.stmt.executeUpdate("DELETE FROM testBug77681");
    }
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:73,代码来源:StatementRegressionTest.java


注:本文中的java.sql.Statement.clearBatch方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。