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


Java PreparedStatement.addBatch方法代码示例

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


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

示例1: addOperations

import java.sql.PreparedStatement; //导入方法依赖的package包/类
private void addOperations(PreparedStatement statement, long testId, String version, MeasuredOperationList operations) throws SQLException {
    for (MeasuredOperation operation : operations) {
        statement.setLong(1, testId);
        statement.setString(2, version);
        statement.setBigDecimal(3, operation.getTotalTime().toUnits(Duration.MILLI_SECONDS).getValue());
        statement.setBigDecimal(4, operation.getConfigurationTime().toUnits(Duration.MILLI_SECONDS).getValue());
        statement.setBigDecimal(5, operation.getExecutionTime().toUnits(Duration.MILLI_SECONDS).getValue());
        statement.setBigDecimal(6, operation.getTotalMemoryUsed().toUnits(DataAmount.BYTES).getValue());
        statement.setBigDecimal(7, operation.getTotalHeapUsage().toUnits(DataAmount.BYTES).getValue());
        statement.setBigDecimal(8, operation.getMaxHeapUsage().toUnits(DataAmount.BYTES).getValue());
        statement.setBigDecimal(9, operation.getMaxUncollectedHeap().toUnits(DataAmount.BYTES).getValue());
        statement.setBigDecimal(10, operation.getMaxCommittedHeap().toUnits(DataAmount.BYTES).getValue());
        if (operation.getCompileTotalTime() != null) {
            statement.setBigDecimal(11, operation.getCompileTotalTime().toUnits(Duration.MILLI_SECONDS).getValue());
        } else {
            statement.setNull(11, Types.DECIMAL);
        }
        if (operation.getGcTotalTime() != null) {
            statement.setBigDecimal(12, operation.getGcTotalTime().toUnits(Duration.MILLI_SECONDS).getValue());
        } else {
            statement.setNull(12, Types.DECIMAL);
        }
        statement.addBatch();
    }
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:26,代码来源:CrossVersionResultsStore.java

示例2: setBatchPreparedStatementParams

import java.sql.PreparedStatement; //导入方法依赖的package包/类
/**
 * 在'PreparedStatement'中设置SQL语句参数.
 * @param pstmt PreparedStatement实例
 * @param paramsArr 不定长数组参数
 * @return PreparedStatement实例
 * @throws SQLException SQL异常
 */
private static PreparedStatement setBatchPreparedStatementParams(PreparedStatement pstmt,
        Object[]... paramsArr) throws SQLException {
    if (paramsArr == null) {
        return pstmt;
    }

    // 遍历批量执行每条语句的数组参数.
    for (Object[] params: paramsArr) {
        if (params == null) {
            continue;
        }
        setParams(pstmt, params);
        pstmt.addBatch();
    }

    return pstmt;
}
 
开发者ID:blinkfox,项目名称:adept,代码行数:25,代码来源:JdbcHelper.java

示例3: addReport

import java.sql.PreparedStatement; //导入方法依赖的package包/类
public void addReport(int reporterid, int victimid, int reason, String description, String chatlog) {
  Connection con = DatabaseConnection.getConnection();
        try {
            PreparedStatement ps = con.prepareStatement("INSERT INTO reports (`reporterid`, `victimid`, `reason`, `description`, `chatlog`) VALUES (?, ?, ?, ?, ?)");
            ps.setInt(1, reporterid);
            ps.setInt(2, victimid);
            ps.setInt(3, reason);
            ps.setString(4, description);
            ps.setString(5, chatlog);
            ps.addBatch();
            ps.executeBatch();
            ps.close();
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
}
 
开发者ID:NovaStory,项目名称:AeroStory,代码行数:17,代码来源:ReportHandler.java

示例4: addAnnReferencesToNakedSecondaryAnnotation

import java.sql.PreparedStatement; //导入方法依赖的package包/类
public void addAnnReferencesToNakedSecondaryAnnotation(int dbAnnId, Tuple secAnnReferencesHolder, Map<String, Integer> dbAnIdByAlvisAnnId) throws ProcessingException {
    PreparedStatement addAnnRefStatement = getPreparedStatement(PreparedStatementId.AddAnnotationReference);
    try {
        int ordNum = 0;
        for (String role : secAnnReferencesHolder.getRoles()) {
            String referencedAnnAlvisId = secAnnReferencesHolder.getArgument(role).getStringId();
            int referencedAnnId = dbAnIdByAlvisAnnId.get(referencedAnnAlvisId);
            addAnnRefStatement.setInt(1, dbAnnId);
            addAnnRefStatement.setInt(2, referencedAnnId);
            addAnnRefStatement.setString(3, role);
            addAnnRefStatement.setInt(4, ordNum++);
            addAnnRefStatement.addBatch();
        }
        addAnnRefStatement.executeBatch();
    } catch (SQLException ex) {
        logger.log(Level.SEVERE, ex.getMessage());
        throw new ProcessingException("Could not add Annotation references", ex);
    }
}
 
开发者ID:Bibliome,项目名称:alvisnlp,代码行数:20,代码来源:ADBBinder.java

示例5: insert

import java.sql.PreparedStatement; //导入方法依赖的package包/类
private long insert(Connection con, List<Map<String, String>> list)
        throws SQLException {
    PreparedStatement ps;

    String sql = "insert into travelrecord (id,user_id,traveldate,fee,days) values(?,?,?,?,?)";
    ps = con.prepareStatement(sql);
    for (Map<String, String> map : list) {
        ps.setLong(1, Long.parseLong(map.get("id")));
        ps.setString(2, (String) map.get("user_id"));
        ps.setString(3, (String) map.get("traveldate"));
        ps.setString(4, (String) map.get("fee"));
        ps.setString(5, (String) map.get("days"));
        ps.addBatch();
    }
    ps.executeBatch();
    con.commit();
    ps.clearBatch();
    ps.close();
    return list.size();
}
 
开发者ID:actiontech,项目名称:dble,代码行数:21,代码来源:TravelRecordInsertJob.java

示例6: testBug39426

import java.sql.PreparedStatement; //导入方法依赖的package包/类
/**
 * Bug #39426 - executeBatch passes most recent PreparedStatement params to
 * StatementInterceptor
 */
public void testBug39426() throws Exception {
    Connection c = null;
    try {
        createTable("testBug39426", "(x int)");
        c = getConnectionWithProps("statementInterceptors=testsuite.regression.StatementRegressionTest$Bug39426Interceptor,useServerPrepStmts=false");
        PreparedStatement ps = c.prepareStatement("insert into testBug39426 values (?)");
        ps.setInt(1, 1);
        ps.addBatch();
        ps.setInt(1, 2);
        ps.addBatch();
        ps.setInt(1, 3);
        ps.addBatch();
        ps.executeBatch();
        List<Integer> vals = Bug39426Interceptor.vals;
        assertEquals(new Integer(1), vals.get(0));
        assertEquals(new Integer(2), vals.get(1));
        assertEquals(new Integer(3), vals.get(2));
    } finally {
        if (c != null) {
            c.close();
        }
    }
}
 
开发者ID:Jugendhackt,项目名称:OpenVertretung,代码行数:28,代码来源:StatementRegressionTest.java

示例7: collect

import java.sql.PreparedStatement; //导入方法依赖的package包/类
@Override
public void collect(Configuration conf, BaseDimension key, BaseStatsValueWritable value, PreparedStatement pstmt,
		IDimensionConverter converter) throws SQLException, IOException {
	// 进行强制后获取对应的值
	StatsUserDimension statsUser = (StatsUserDimension) key;
	IntWritable activeUserValue = (IntWritable) ((MapWritableValue) value).getValue().get(new IntWritable(-1));

	// 进行参数设置
	int i = 0;
	pstmt.setInt(++i, converter.getDimensionIdByValue(statsUser.getStatsCommon().getPlatform()));
	pstmt.setInt(++i, converter.getDimensionIdByValue(statsUser.getStatsCommon().getDate()));
	pstmt.setInt(++i, converter.getDimensionIdByValue(statsUser.getBrowser()));
	pstmt.setInt(++i, activeUserValue.get());
	pstmt.setString(++i, conf.get(GlobalConstants.RUNNING_DATE_PARAMES));
	pstmt.setInt(++i, activeUserValue.get());

	// 添加到batch中
	pstmt.addBatch();
}
 
开发者ID:liuhaozzu,项目名称:big_data,代码行数:20,代码来源:ActiveUserBrowserCollector.java

示例8: insert

import java.sql.PreparedStatement; //导入方法依赖的package包/类
private long insert(Connection con, List<Map<String, String>> list)
		throws SQLException {
	PreparedStatement ps;

	String sql = "insert into travelrecord (id,user_id,traveldate,fee,days) values(?,?,?,?,?)";
	ps = con.prepareStatement(sql);
	for (Map<String, String> map : list) {
		ps.setLong(1, Long.parseLong(map.get("id")));
		ps.setString(2, (String) map.get("user_id"));
		ps.setString(3, (String) map.get("traveldate"));
		ps.setString(4, (String) map.get("fee"));
		ps.setString(5, (String) map.get("days"));
		ps.addBatch();
	}
	ps.executeBatch();
	con.commit();
	ps.clearBatch();
	ps.close();
	return list.size();
}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:21,代码来源:TravelRecordInsertJob.java

示例9: lowerRequestedFlag

import java.sql.PreparedStatement; //导入方法依赖的package包/类
@Override
public void lowerRequestedFlag(Connection txn, ContactId c,
		Collection<MessageId> requested) throws DbException {
	PreparedStatement ps = null;
	try {
		String sql = "UPDATE statuses SET requested = FALSE"
				+ " WHERE messageId = ? AND contactId = ?";
		ps = txn.prepareStatement(sql);
		ps.setInt(2, c.getInt());
		for (MessageId m : requested) {
			ps.setBytes(1, m.getBytes());
			ps.addBatch();
		}
		int[] batchAffected = ps.executeBatch();
		if (batchAffected.length != requested.size())
			throw new DbStateException();
		for (int rows: batchAffected) {
			if (rows < 0) throw new DbStateException();
			if (rows > 1) throw new DbStateException();
		}
		ps.close();
	} catch (SQLException e) {
		tryToClose(ps);
		throw new DbException(e);
	}
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:27,代码来源:JdbcDatabase.java

示例10: lowerAckFlag

import java.sql.PreparedStatement; //导入方法依赖的package包/类
@Override
public void lowerAckFlag(Connection txn, ContactId c,
		Collection<MessageId> acked) throws DbException {
	PreparedStatement ps = null;
	try {
		String sql = "UPDATE statuses SET ack = FALSE"
				+ " WHERE messageId = ? AND contactId = ?";
		ps = txn.prepareStatement(sql);
		ps.setInt(2, c.getInt());
		for (MessageId m : acked) {
			ps.setBytes(1, m.getBytes());
			ps.addBatch();
		}
		int[] batchAffected = ps.executeBatch();
		if (batchAffected.length != acked.size())
			throw new DbStateException();
		for (int rows : batchAffected) {
			if (rows < 0) throw new DbStateException();
			if (rows > 1) throw new DbStateException();
		}
		ps.close();
	} catch (SQLException e) {
		tryToClose(ps);
		throw new DbException(e);
	}
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:27,代码来源:JdbcDatabase.java

示例11: getPreparedStatement

import java.sql.PreparedStatement; //导入方法依赖的package包/类
@Override
/** {@inheritDoc} */
protected PreparedStatement getPreparedStatement(
    List<SqoopRecord> userRecords) throws SQLException {

  PreparedStatement stmt = null;

  // Synchronize on connection to ensure this does not conflict
  // with the operations in the update thread.
  Connection conn = getConnection();
  synchronized (conn) {
    stmt = conn.prepareStatement(getUpdateStatement());
  }

  // Inject the record parameters into the UPDATE and WHERE clauses.  This
  // assumes that the update key column is the last column serialized in
  // by the underlying record. Our code auto-gen process for exports was
  // responsible for taking care of this constraint.
  for (SqoopRecord record : userRecords) {
    record.write(stmt, 0);
    stmt.addBatch();
  }

  return stmt;
}
 
开发者ID:aliyun,项目名称:aliyun-maxcompute-data-collectors,代码行数:26,代码来源:UpdateOutputFormat.java

示例12: addOperations

import java.sql.PreparedStatement; //导入方法依赖的package包/类
private void addOperations(PreparedStatement statement, long executionId, BuildDisplayInfo displayInfo, MeasuredOperationList operations) throws SQLException {
    for (MeasuredOperation operation : operations) {
        statement.setLong(1, executionId);
        statement.setString(2, displayInfo.getProjectName());
        statement.setString(3, displayInfo.getDisplayName());
        statement.setObject(4, toArray(displayInfo.getTasksToRun()));
        statement.setObject(5, toArray(displayInfo.getArgs()));
        statement.setObject(6, toArray(displayInfo.getGradleOpts()));
        statement.setObject(7, displayInfo.getDaemon());
        statement.setBigDecimal(8, operation.getTotalTime().toUnits(Duration.MILLI_SECONDS).getValue());
        statement.setBigDecimal(9, operation.getConfigurationTime().toUnits(Duration.MILLI_SECONDS).getValue());
        statement.setBigDecimal(10, operation.getExecutionTime().toUnits(Duration.MILLI_SECONDS).getValue());
        statement.setBigDecimal(11, operation.getTotalMemoryUsed().toUnits(DataAmount.BYTES).getValue());
        statement.setBigDecimal(12, operation.getTotalHeapUsage().toUnits(DataAmount.BYTES).getValue());
        statement.setBigDecimal(13, operation.getMaxHeapUsage().toUnits(DataAmount.BYTES).getValue());
        statement.setBigDecimal(14, operation.getMaxUncollectedHeap().toUnits(DataAmount.BYTES).getValue());
        statement.setBigDecimal(15, operation.getMaxCommittedHeap().toUnits(DataAmount.BYTES).getValue());
        if (operation.getCompileTotalTime() != null) {
            statement.setBigDecimal(16, operation.getCompileTotalTime().toUnits(Duration.MILLI_SECONDS).getValue());
        } else {
            statement.setNull(16, Types.DECIMAL);
        }
        if (operation.getGcTotalTime() != null) {
            statement.setBigDecimal(17, operation.getGcTotalTime().toUnits(Duration.MILLI_SECONDS).getValue());
        } else {
            statement.setNull(17, Types.DECIMAL);
        }
        statement.addBatch();
    }
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:31,代码来源:BaseCrossBuildResultsStore.java

示例13: testBug20029

import java.sql.PreparedStatement; //导入方法依赖的package包/类
/**
 * Tests fix for BUG#20029 - NPE thrown from executeBatch().
 * 
 * @throws Exception
 */
public void testBug20029() throws Exception {
    createTable("testBug20029", ("(field1 int)"));

    long initialTimeout = 20; // may need to raise this depending on environment we try and do this automatically in this testcase

    for (int i = 0; i < 10; i++) {
        final Connection toBeKilledConn = getConnectionWithProps(new Properties());
        final long timeout = initialTimeout;
        PreparedStatement toBeKilledPstmt = null;

        try {
            toBeKilledPstmt = ((com.mysql.jdbc.Connection) toBeKilledConn).clientPrepareStatement("INSERT INTO testBug20029 VALUES (?)");

            for (int j = 0; j < 1000; j++) {
                toBeKilledPstmt.setInt(1, j);
                toBeKilledPstmt.addBatch();
            }

            Thread t = new Thread() {
                @Override
                public void run() {
                    try {
                        sleep(timeout);
                        toBeKilledConn.close();
                    } catch (Throwable thr) {

                    }
                }
            };

            t.start();

            try {
                if (!toBeKilledConn.isClosed()) {
                    initialTimeout *= 2;
                    continue;
                }

                toBeKilledPstmt.executeBatch();
                fail("Should've caught a SQLException for the statement being closed here");
            } catch (BatchUpdateException batchEx) {
                assertEquals("08003", batchEx.getSQLState());
                break;
            } catch (SQLException sqlEx) {
                assertEquals("08003", sqlEx.getSQLState());
                break;
            }

            fail("Connection didn't close while in the middle of PreparedStatement.executeBatch()");
        } finally {
            if (toBeKilledPstmt != null) {
                toBeKilledPstmt.close();
            }

            if (toBeKilledConn != null) {
                toBeKilledConn.close();
            }
        }
    }
}
 
开发者ID:rafallis,项目名称:BibliotecaPS,代码行数:66,代码来源:StatementRegressionTest.java

示例14: populateTable

import java.sql.PreparedStatement; //导入方法依赖的package包/类
static void populateTable(Connection con) throws SQLException {

        long      startTime = System.currentTimeMillis();
        Timestamp now       = new Timestamp(startTime);

        con.setAutoCommit(false);

        String            sql  = createInsertSQL(true, false);
        PreparedStatement prep = con.prepareStatement(sql);

        prep.clearParameters();
        prep.setString(1, "xxx");
        prep.setTimestamp(2, now);    // last_update

        for (int ii = 0; ii < DECIMAL_FIELDS_PER_DATASET; ii++) {
            prep.setDouble(ii + 3, 0.123456789);    // Wert
        }

        prep.addBatch();
        prep.setString(1, "yyy");
        prep.setTimestamp(2, now);    // last_update

        for (int ii = 0; ii < DECIMAL_FIELDS_PER_DATASET; ii++) {
            prep.setDouble(ii + 3, 0.123456789);    // Wert
        }

        prep.addBatch();

        int[] updateCounts = prep.executeBatch();

        con.setAutoCommit(true);
        prep.close();
    }
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:34,代码来源:TestBatchBug.java

示例15: getPreparedStatement

import java.sql.PreparedStatement; //导入方法依赖的package包/类
/**
  * {@inheritDoc}
  */
 @Override
 protected PreparedStatement getPreparedStatement(
     List<SqoopRecord> userRecords) throws SQLException {

   PreparedStatement stmt = null;

   // Synchronize on connection to ensure this does not conflict
   // with the operations in the update thread.
   Connection conn = getConnection();
   synchronized (conn) {
stmt = conn.prepareStatement(getUpdateStatement(userRecords.size()));
   }

   // Inject the record parameters into the UPDATE and WHERE clauses.  This
   // assumes that the update key column is the last column serialized in
   // by the underlying record. Our code auto-gen process for exports was
   // responsible for taking care of this constraint.
   int i = 0;
   for (SqoopRecord record : userRecords) {
     record.write(stmt, i);
     i += columnNames.length;
   }
   stmt.addBatch();

   return stmt;
 }
 
开发者ID:aliyun,项目名称:aliyun-maxcompute-data-collectors,代码行数:30,代码来源:MySQLUpsertOutputFormat.java


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