本文整理汇总了Java中org.apache.commons.dbutils.QueryRunner.update方法的典型用法代码示例。如果您正苦于以下问题:Java QueryRunner.update方法的具体用法?Java QueryRunner.update怎么用?Java QueryRunner.update使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.dbutils.QueryRunner
的用法示例。
在下文中一共展示了QueryRunner.update方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: insert
import org.apache.commons.dbutils.QueryRunner; //导入方法依赖的package包/类
public static int insert(Connection dbconn, final String logContext, final int messageRef,
final IHttpService httpService, final String clientIp, final String requestUrl, final String method,
final byte[] reqdata) throws SQLException {
QueryRunner runner = new QueryRunner();
String sql =
"insert into proxy_history(log_context, message_ref, protocol, host, port, client_ip, url, request_method, request_bytes, send_at)"
+ " values (?, ?, ?, ?, ?, ?, ?, ?, ?, now())";
return runner.update(
dbconn,
sql,
logContext,
messageRef,
httpService.getProtocol(),
httpService.getHost(),
httpService.getPort(),
clientIp,
requestUrl,
method,
reqdata);
}
示例2: clearMySQLTestDB
import org.apache.commons.dbutils.QueryRunner; //导入方法依赖的package包/类
private static void clearMySQLTestDB() throws SQLException {
Props props = new Props();
props.put("database.type", "mysql");
props.put("mysql.host", "localhost");
props.put("mysql.port", "3306");
props.put("mysql.database", "");
props.put("mysql.user", "root");
props.put("mysql.password", "");
props.put("mysql.numconnections", 10);
DataSource datasource = DataSourceUtils.getDataSource(props);
QueryRunner runner = new QueryRunner(datasource);
try {
runner.update("drop database azkabanunittest");
} catch (SQLException e) {
}
runner.update("create database azkabanunittest");
}
示例3: createSequence
import org.apache.commons.dbutils.QueryRunner; //导入方法依赖的package包/类
public void createSequence() {
List items = db.findRecords("SHOW TABLES LIKE 'stallion_tickets'");
if (items.size() > 0) {
return;
}
QueryRunner q = db.newQuery();
try {
q.update("CREATE TABLE `stallion_tickets` (\n" +
" `id` int(11) unsigned NOT NULL AUTO_INCREMENT,\n" +
" `ticket_name` varchar(10) DEFAULT NULL,\n" +
" PRIMARY KEY (`id`),\n" +
" UNIQUE KEY `ticket_name_unique` (`ticket_name`)\n" +
") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;");
db.execute("INSERT INTO stallion_tickets (`ticket_name`) VALUES('a')");
} catch(Exception e) {
Log.exception(e, "Error creating tickets table");
}
}
示例4: updateNextExecTime
import org.apache.commons.dbutils.QueryRunner; //导入方法依赖的package包/类
@Override
public void updateNextExecTime(Schedule s) throws ScheduleManagerException {
logger.info("Update schedule " + s.getScheduleName() + " into db. ");
Connection connection = getConnection();
QueryRunner runner = new QueryRunner();
try {
runner.update(connection, UPDATE_NEXT_EXEC_TIME, s.getNextExecTime(),
s.getProjectId(), s.getFlowName());
} catch (SQLException e) {
e.printStackTrace();
logger.error(UPDATE_NEXT_EXEC_TIME + " failed.", e);
throw new ScheduleManagerException("Update schedule "
+ s.getScheduleName() + " into db failed. ", e);
} finally {
DbUtils.closeQuietly(connection);
}
}
示例5: postEvent
import org.apache.commons.dbutils.QueryRunner; //导入方法依赖的package包/类
@Override
public boolean postEvent(Project project, EventType type, String user,
String message) {
QueryRunner runner = createQueryRunner();
final String INSERT_PROJECT_EVENTS =
"INSERT INTO project_events (project_id, event_type, event_time, username, message) values (?,?,?,?,?)";
long updateTime = System.currentTimeMillis();
try {
runner.update(INSERT_PROJECT_EVENTS, project.getId(), type.getNumVal(),
updateTime, user, message);
} catch (SQLException e) {
e.printStackTrace();
return false;
}
return true;
}
示例6: updateDescription
import org.apache.commons.dbutils.QueryRunner; //导入方法依赖的package包/类
@Override
public void updateDescription(Project project, String description, String user)
throws ProjectManagerException {
QueryRunner runner = createQueryRunner();
final String UPDATE_PROJECT_DESCRIPTION =
"UPDATE projects SET description=?,modified_time=?,last_modified_by=? WHERE id=?";
long updateTime = System.currentTimeMillis();
try {
runner.update(UPDATE_PROJECT_DESCRIPTION, description, updateTime, user,
project.getId());
project.setDescription(description);
project.setLastModifiedTimestamp(updateTime);
project.setLastModifiedUser(user);
} catch (SQLException e) {
logger.error(e);
throw new ProjectManagerException("Error marking project "
+ project.getName() + " as inactive", e);
}
}
示例7: uploadFlow
import org.apache.commons.dbutils.QueryRunner; //导入方法依赖的package包/类
private void uploadFlow(Connection connection, Project project, int version,
Flow flow, EncodingType encType) throws ProjectManagerException,
IOException {
QueryRunner runner = new QueryRunner();
String json = JSONUtils.toJSON(flow.toObject());
byte[] stringData = json.getBytes("UTF-8");
byte[] data = stringData;
if (encType == EncodingType.GZIP) {
data = GZIPUtils.gzipBytes(stringData);
}
logger.info("Flow upload " + flow.getId() + " is byte size " + data.length);
final String INSERT_FLOW =
"INSERT INTO project_flows (project_id, version, flow_id, modified_time, encoding_type, json) values (?,?,?,?,?,?)";
try {
runner.update(connection, INSERT_FLOW, project.getId(), version,
flow.getId(), System.currentTimeMillis(), encType.getNumVal(), data);
} catch (SQLException e) {
throw new ProjectManagerException("Error inserting flow " + flow.getId(),
e);
}
}
示例8: updateExecutableReference
import org.apache.commons.dbutils.QueryRunner; //导入方法依赖的package包/类
@Override
public boolean updateExecutableReference(int execId, long updateTime)
throws ExecutorManagerException {
final String DELETE =
"UPDATE active_executing_flows set update_time=? WHERE exec_id=?";
QueryRunner runner = createQueryRunner();
int updateNum = 0;
try {
updateNum = runner.update(DELETE, updateTime, execId);
} catch (SQLException e) {
throw new ExecutorManagerException(
"Error deleting active flow reference " + execId, e);
}
// Should be 1.
return updateNum > 0;
}
示例9: removeTrigger
import org.apache.commons.dbutils.QueryRunner; //导入方法依赖的package包/类
@Override
public void removeTrigger(Trigger t) throws TriggerLoaderException {
logger.info("Removing trigger " + t.toString() + " from db.");
QueryRunner runner = createQueryRunner();
try {
int removes = runner.update(REMOVE_TRIGGER, t.getTriggerId());
if (removes == 0) {
throw new TriggerLoaderException("No trigger has been removed.");
}
} catch (SQLException e) {
logger.error(REMOVE_TRIGGER + " failed.");
throw new TriggerLoaderException("Remove trigger " + t.toString()
+ " from db failed. ", e);
}
}
示例10: clearMySQLTestDb
import org.apache.commons.dbutils.QueryRunner; //导入方法依赖的package包/类
private static void clearMySQLTestDb() throws SQLException {
Props props = new Props();
props.put("database.type", "mysql");
props.put("mysql.host", "localhost");
props.put("mysql.port", "3306");
props.put("mysql.database", "");
props.put("mysql.user", "root");
props.put("mysql.password", "");
props.put("mysql.numconnections", 10);
DataSource datasource = DataSourceUtils.getDataSource(props);
QueryRunner runner = new QueryRunner(datasource);
try {
runner.update("drop database azkabanunittest");
} catch (SQLException e) {
}
runner.update("create database azkabanunittest");
}
示例11: updateCharset
import org.apache.commons.dbutils.QueryRunner; //导入方法依赖的package包/类
public static int updateCharset(Connection dbconn, final String logContext, final int messageRef,
final String requestCharset, final String responseCharset) throws SQLException {
String sql =
"update proxy_history set request_charset = ?, response_charset = ? where log_context = ? and message_ref = ?";
QueryRunner runner = new QueryRunner();
return runner.update(
dbconn,
sql,
getCharset(requestCharset).name(),
getCharset(responseCharset).name(),
logContext,
messageRef);
}
示例12: update
import org.apache.commons.dbutils.QueryRunner; //导入方法依赖的package包/类
public static int update(Connection dbconn, final String logContext, final int messageRef, final byte[] resdata,
final int statusCode) throws SQLException {
QueryRunner runner = new QueryRunner();
String sql =
"update proxy_history set response_bytes = ?, response_status_code = ?, received_at = now() "
+ " where log_context = ? and message_ref = ?";
return runner.update(dbconn, sql, resdata, statusCode, logContext, messageRef);
}
示例13: executeUpdate
import org.apache.commons.dbutils.QueryRunner; //导入方法依赖的package包/类
@Override
public void executeUpdate(String query, Connection conn) {
QueryRunner qRunner = getQueryRunner();
try {
qRunner.update(conn, query);
} catch (SQLException e) {
throw new RTSQLException(e);
}
}
示例14: findPlayers
import org.apache.commons.dbutils.QueryRunner; //导入方法依赖的package包/类
@Override
public List<PlayerRow> findPlayers(int start, int limit) {
QueryRunner runner = getQueryRunner();
try(Connection connection = dataSource.getConnection()) {
runner.update(connection, "SET @rownum := ?;", start);
return runner.query(connection,
"SELECT @rownum := @rownum + 1 AS rank, id, name, level, experience FROM Player WHERE isCheater=0 " +
"ORDER BY experience DESC, LOWER(name) ASC " +
"LIMIT ?, ?;",
new BeanListHandler<>(PlayerRow.class), start, limit);
} catch (SQLException e) {
throw new GatewayError("Failed to select player rows from database", e);
}
}
示例15: addActiveExecutableReference
import org.apache.commons.dbutils.QueryRunner; //导入方法依赖的package包/类
@Override
public void addActiveExecutableReference(ExecutionReference reference)
throws ExecutorManagerException {
final String INSERT =
"INSERT INTO active_executing_flows "
+ "(exec_id, update_time) values (?,?)";
QueryRunner runner = createQueryRunner();
try {
runner.update(INSERT, reference.getExecId(), reference.getUpdateTime());
} catch (SQLException e) {
throw new ExecutorManagerException(
"Error updating active flow reference " + reference.getExecId(), e);
}
}