本文整理汇总了Java中org.springframework.jdbc.core.simple.SimpleJdbcTemplate.update方法的典型用法代码示例。如果您正苦于以下问题:Java SimpleJdbcTemplate.update方法的具体用法?Java SimpleJdbcTemplate.update怎么用?Java SimpleJdbcTemplate.update使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.jdbc.core.simple.SimpleJdbcTemplate
的用法示例。
在下文中一共展示了SimpleJdbcTemplate.update方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: logTime
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; //导入方法依赖的package包/类
@Override
@SuppressWarnings("pmd.AvoidDuplicateLiterals")
public int logTime(CitationVO citacaoIssueVO) {
Integer activityId = this.findDefaultActivityId();
SimpleJdbcTemplate simpleJdbcTemplate = getSimpleJdbcTemplate();
@SuppressWarnings("pmd.AvoidDuplicateLiterals")
String logTimeQuery = " INSERT INTO time_entries( " +
" project_id, " +
" user_id, " +
" issue_id, " +
" hours, " +
" comments, " +
" activity_id, " +
" spent_on, " +
" tyear, " +
" tmonth, " +
" tweek, " +
" created_on, " +
" updated_on) " +
" VALUES(" +
" ?, ?, ?, ?, ?, ?, " +
"curdate(), year(curdate()), month(curdate()), week(curdate()), curdate(), curdate())";
Integer affected = simpleJdbcTemplate.update(logTimeQuery,
citacaoIssueVO.getIssueVO().getProjectVO().getId(),
citacaoIssueVO.getRedmineUserVO().getId(),
citacaoIssueVO.getIssueVO().getId(),
citacaoIssueVO.getHorasDespendidas(),
"Lançamento automático de esforço a partir da mensagem de commit!",
activityId);
return affected;
}
示例2: createTempTable
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; //导入方法依赖的package包/类
public static String createTempTable(DataSource dataSource, String tableName, ColumnDef... content) {
SimpleJdbcTemplate jdbc = new SimpleJdbcTemplate(dataSource);
String[] tokens = new String[content.length];
Arrays.fill(tokens, "?");
String sqlCreateTable = "create temp table " + tableName + " ( " + CollectionUtil.toString(content, ",") + ") with no log";
String sqlInsert = "insert into tbcdids values (" + CollectionUtil.toString(tokens, ",") + ")";
jdbc.update(sqlCreateTable);
jdbc.batchUpdate(sqlInsert, makeListOfObjectArray(content));
return tableName;
}
示例3: handleQueryTag
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; //导入方法依赖的package包/类
private Object handleQueryTag(String sql, MapSqlParameterSource namedParameters, SimpleJdbcTemplate template) {
Object result = null;
if (sql.trim().toLowerCase().startsWith("select")) {
result = template.queryForList(sql, namedParameters);
} else {
result = template.update(sql, namedParameters);
}
return result;
}
示例4: handleInsert
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; //导入方法依赖的package包/类
/**
* @param sql
* @param namedParameters
* @param stmt
* @param template
* @return
*/
@SuppressWarnings("unchecked")
private Object handleInsert(String sql, MapSqlParameterSource namedParameters, Insert stmt, SimpleJdbcTemplate template) {
Object result = null;
int rowsUpdate = template.update(sql, namedParameters);
result = String.valueOf(rowsUpdate);
return result;
}
示例5: deleteFromTables
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; //导入方法依赖的package包/类
/**
* Delete all rows from the specified tables.
* @param simpleJdbcTemplate the SimpleJdbcTemplate with which to perform JDBC operations
* @param tableNames the names of the tables from which to delete
* @return the total number of rows deleted from all specified tables
*/
public static int deleteFromTables(SimpleJdbcTemplate simpleJdbcTemplate, String... tableNames) {
int totalRowCount = 0;
for (String tableName : tableNames) {
int rowCount = simpleJdbcTemplate.update("DELETE FROM " + tableName);
totalRowCount += rowCount;
if (logger.isInfoEnabled()) {
logger.info("Deleted " + rowCount + " rows from table " + tableName);
}
}
return totalRowCount;
}
示例6: createPersonTable
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; //导入方法依赖的package包/类
protected static void createPersonTable(SimpleJdbcTemplate simpleJdbcTemplate) {
try {
simpleJdbcTemplate.update("CREATE TABLE person (name VARCHAR(20) NOT NULL, PRIMARY KEY(name))");
}
catch (DataAccessException dae) {
// ignore
}
}
示例7: createPersonTable
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; //导入方法依赖的package包/类
protected static void createPersonTable(final SimpleJdbcTemplate simpleJdbcTemplate) {
try {
simpleJdbcTemplate.update("CREATE TABLE person (name VARCHAR(20) NOT NULL, PRIMARY KEY(name))");
}
catch (DataAccessException dae) {
/* ignore */
}
}
示例8: createPersonTable
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; //导入方法依赖的package包/类
protected static void createPersonTable(final SimpleJdbcTemplate simpleJdbcTemplate) {
try {
simpleJdbcTemplate.update("CREATE TABLE person (name VARCHAR(20) NOT NULL, PRIMARY KEY(name))");
}
catch (final BadSqlGrammarException bsge) {
/* ignore */
}
}
示例9: init
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; //导入方法依赖的package包/类
private void init() throws Exception {
super.setUp();
ConfigurableApplicationContext context = DbMasterTestUtils.getContext(getDatabaseType());
_secMaster = (DbSecurityMaster) context.getBean(getDatabaseType() + "DbSecurityMaster");
// id bigint not null,
// oid bigint not null,
// ver_from_instant timestamp not null,
// ver_to_instant timestamp not null,
// corr_from_instant timestamp not null,
// corr_to_instant timestamp not null,
// name varchar(255) not null,
// sec_type varchar(255) not null,
Instant now = Instant.now();
_secMaster.setClock(Clock.fixed(now, ZoneOffset.UTC));
_version1Instant = now.minusSeconds(100);
_version2Instant = now.minusSeconds(50);
s_logger.debug("test data now: {}", _version1Instant);
s_logger.debug("test data later: {}", _version2Instant);
final SimpleJdbcTemplate template = _secMaster.getDbConnector().getJdbcTemplate();
template.update("INSERT INTO sec_security VALUES (?,?,?,?,?, ?,?,?,?)",
101, 101, toSqlTimestamp(_version1Instant), MAX_SQL_TIMESTAMP, toSqlTimestamp(_version1Instant), MAX_SQL_TIMESTAMP, "TestSecurity101", "EQUITY", "D");
template.update("INSERT INTO sec_security VALUES (?,?,?,?,?, ?,?,?,?)",
102, 102, toSqlTimestamp(_version1Instant), MAX_SQL_TIMESTAMP, toSqlTimestamp(_version1Instant), MAX_SQL_TIMESTAMP, "TestSecurity102", "EQUITY", "D");
template.update("INSERT INTO sec_security VALUES (?,?,?,?,?, ?,?,?,?)",
201, 201, toSqlTimestamp(_version1Instant), toSqlTimestamp(_version2Instant), toSqlTimestamp(_version1Instant), MAX_SQL_TIMESTAMP, "TestSecurity201", "EQUITY", "D");
template.update("INSERT INTO sec_security VALUES (?,?,?,?,?, ?,?,?,?)",
202, 201, toSqlTimestamp(_version2Instant), MAX_SQL_TIMESTAMP, toSqlTimestamp(_version2Instant), MAX_SQL_TIMESTAMP, "TestSecurity202", "EQUITY", "D");
_totalSecurities = 3;
// id bigint not null,
// key_scheme varchar(255) not null,
// key_value varchar(255) not null,
template.update("INSERT INTO sec_idkey VALUES (?,?,?)",
1, "A", "B");
template.update("INSERT INTO sec_idkey VALUES (?,?,?)",
2, "C", "D");
template.update("INSERT INTO sec_idkey VALUES (?,?,?)",
3, "E", "F");
template.update("INSERT INTO sec_idkey VALUES (?,?,?)",
4, "GH", "HI");
// security_id bigint not null,
// idkey_id bigint not null,
template.update("INSERT INTO sec_security2idkey VALUES (?,?)",
101, 1);
template.update("INSERT INTO sec_security2idkey VALUES (?,?)",
101, 2);
template.update("INSERT INTO sec_security2idkey VALUES (?,?)",
101, 3);
template.update("INSERT INTO sec_security2idkey VALUES (?,?)",
102, 1);
template.update("INSERT INTO sec_security2idkey VALUES (?,?)",
102, 2);
template.update("INSERT INTO sec_security2idkey VALUES (?,?)",
102, 4);
template.update("INSERT INTO sec_security2idkey VALUES (?,?)",
201, 2);
template.update("INSERT INTO sec_security2idkey VALUES (?,?)",
201, 3);
template.update("INSERT INTO sec_security2idkey VALUES (?,?)",
202, 2);
template.update("INSERT INTO sec_security2idkey VALUES (?,?)",
202, 3);
}
示例10: onSetUpBeforeTransaction
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; //导入方法依赖的package包/类
@Override
protected void onSetUpBeforeTransaction() throws Exception {
SimpleJdbcTemplate template = new SimpleJdbcTemplate((DataSource)applicationContext.getBean("dataSource"));
template.update(DDL);
}
示例11: execute
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; //导入方法依赖的package包/类
private Object execute(RDBDatasource ds, SQLQuery stmt, Map<String, AdaptedToService> paramsIn, Set outputMapping, Filters filters, DataIdentifier dataId) {
Long oldChecksum = null;
if (isConcurrentModificationEnabled()) {
oldChecksum = ConflictDetectionUtil.removeChecksum(paramsIn);
}
String[] inputKeys = null;
Map<String, Object> paramIns = new HashMap<String, Object>();
if (paramsIn != null) {
paramIns = narrow(paramsIn);
inputKeys = (String[]) paramIns.keySet().toArray(new String[paramIns.size()]);
}
MapSqlParameterSource namedParameters = new MapSqlParameterSource(paramIns);
Object result = null;
isCountOnly = DataStore.findValue(dataId, DataStore.KEY_WORD_COUNT) != null;
String sql = QueryToStringCreator.toString(stmt, namedParameters, inputKeys, outputMapping);
Map values = namedParameters.getValues();
if ((values != null) && (values.size() > 0)) {
Map replacementMap = new HashMap<String, Object>();
for (String key : inputKeys) {
if (values.containsKey(key.toUpperCase())) {
replacementMap.put(key, values.get(key.toUpperCase()));
}
if (values.containsKey(key.toLowerCase())) {
replacementMap.put(key, values.get(key.toLowerCase()));
}
}
namedParameters.addValues(replacementMap);
}
logger.info("Executing SQL: " + sql);
SimpleJdbcTemplate template = new SimpleJdbcTemplate(ds.getDataSource());
try {
Connection conn = ds.getDataSource().getConnection();
dialect = getDatabaseDialect(conn);
DataSourceUtils.releaseConnection(conn, ds.getDataSource());
} catch (SQLException e) {
ExceptionHelper.printStackTrace(e);
}
if (stmt instanceof Select) {
result = handleSelect(sql, namedParameters, (Select) stmt, template, filters);
if (!isCountOnly && isConcurrentModificationEnabled()) {
ConflictDetectionUtil.addChecksums((List<Map<String, Object>>) result, sql);
}
} else if (stmt instanceof Insert) {
result = handleInsert(sql, namedParameters, (Insert) stmt, template);
if (isConcurrentModificationEnabled()) {
DataStore.store(dataId, DataStore.KEY_SERVICE_MODIFY);
}
} else if (stmt instanceof SQLOnly) {
result = handleQueryTag(sql, namedParameters, template);
} else {
if (isConcurrentModificationEnabled()) {
ConflictDetectionUtil.validateChecksum(template, sql, namedParameters.getValues(), oldChecksum);
}
template.update(sql, namedParameters);
if (isConcurrentModificationEnabled()) {
DataStore.store(dataId, DataStore.KEY_SERVICE_MODIFY);
}
}
return result;
}
示例12: clearPersonTable
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; //导入方法依赖的package包/类
protected static int clearPersonTable(SimpleJdbcTemplate simpleJdbcTemplate) {
return simpleJdbcTemplate.update("DELETE FROM person");
}
示例13: addPerson
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; //导入方法依赖的package包/类
protected static int addPerson(SimpleJdbcTemplate simpleJdbcTemplate, String name) {
return simpleJdbcTemplate.update("INSERT INTO person VALUES(?)", name);
}
示例14: deletePerson
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; //导入方法依赖的package包/类
protected static int deletePerson(SimpleJdbcTemplate simpleJdbcTemplate, String name) {
return simpleJdbcTemplate.update("DELETE FROM person WHERE name=?", name);
}
示例15: addPerson
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; //导入方法依赖的package包/类
protected static int addPerson(final SimpleJdbcTemplate simpleJdbcTemplate, final String name) {
return simpleJdbcTemplate.update("INSERT INTO person VALUES(?)", name);
}