org.springframework.jdbc.core.JdbcTemplate.update()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(6.4k)|赞(0)|评价(0)|浏览(175)

本文整理了Java中org.springframework.jdbc.core.JdbcTemplate.update()方法的一些代码示例,展示了JdbcTemplate.update()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JdbcTemplate.update()方法的具体详情如下:
包路径:org.springframework.jdbc.core.JdbcTemplate
类名称:JdbcTemplate
方法名:update

JdbcTemplate.update介绍

暂无

代码示例

代码示例来源:origin: spring-projects/spring-framework

@Override
public int update(PreparedStatementCreator psc) throws DataAccessException {
  return update(psc, (PreparedStatementSetter) null);
}

代码示例来源:origin: spring-projects/spring-framework

protected void deleteFromTables(String... tableNames) {
  for (String tableName : tableNames) {
    this.jdbcTemplate.update("DELETE FROM " + tableName);
  }
  this.zappedTables = true;
}

代码示例来源:origin: spring-projects/spring-framework

protected void insertPerson(String firstName) {
  String INSERT_PERSON = "INSERT INTO PERSON (ID, FIRST_NAME, LAST_NAME) VALUES (?, ?, ?)";
  jdbcTemplate.update(INSERT_PERSON, 1, firstName, "Blair");
}

代码示例来源:origin: spring-projects/spring-framework

@Override
public int update(String sql, Object[] args, int[] argTypes) throws DataAccessException {
  return update(sql, newArgTypePreparedStatementSetter(args, argTypes));
}

代码示例来源:origin: spring-projects/spring-framework

@Override
public int update(String sql, @Nullable PreparedStatementSetter pss) throws DataAccessException {
  return update(new SimplePreparedStatementCreator(sql), pss);
}

代码示例来源:origin: spring-projects/spring-framework

@Override
public int update(String sql, @Nullable Object... args) throws DataAccessException {
  return update(sql, newArgPreparedStatementSetter(args));
}

代码示例来源:origin: spring-projects/spring-framework

protected int deletePerson(String name) {
  return jdbcTemplate.update("DELETE FROM person WHERE name=?", name);
}

代码示例来源:origin: spring-projects/spring-framework

private int deletePerson(String name) {
  return jdbcTemplate.update("DELETE FROM person WHERE name=?", name);
}

代码示例来源:origin: spring-projects/spring-framework

private int createPerson(String name) {
  return jdbcTemplate.update("INSERT INTO person VALUES(?)", name);
}

代码示例来源:origin: spring-projects/spring-framework

private int deletePerson(String name) {
  return super.jdbcTemplate.update("DELETE FROM person WHERE name=?", name);
}

代码示例来源:origin: spring-projects/spring-framework

protected static int clearPersonTable(JdbcTemplate jdbcTemplate) {
  return jdbcTemplate.update("DELETE FROM person");
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Delegate method to execute the insert.
 */
private int executeInsertInternal(List<?> values) {
  if (logger.isDebugEnabled()) {
    logger.debug("The following parameters are used for insert " + getInsertString() + " with: " + values);
  }
  return getJdbcTemplate().update(getInsertString(), values.toArray(), getInsertTypes());
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Generic method to execute the update given parameters.
 * All other update methods invoke this method.
 * @param params array of parameters objects
 * @return the number of rows affected by the update
 */
public int update(Object... params) throws DataAccessException {
  validateParameters(params);
  int rowsAffected = getJdbcTemplate().update(newPreparedStatementCreator(params));
  checkRowsAffected(rowsAffected);
  return rowsAffected;
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void testPreparedStatementSetterSucceeds() throws Exception {
  final String sql = "UPDATE FOO SET NAME=? WHERE ID = 1";
  final String name = "Gary";
  int expectedRowsUpdated = 1;
  given(this.preparedStatement.executeUpdate()).willReturn(expectedRowsUpdated);
  PreparedStatementSetter pss = ps -> ps.setString(1, name);
  int actualRowsUpdated = new JdbcTemplate(this.dataSource).update(sql, pss);
  assertEquals("updated correct # of rows", actualRowsUpdated, expectedRowsUpdated);
  verify(this.preparedStatement).setString(1, name);
  verify(this.preparedStatement).close();
  verify(this.connection).close();
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void testSqlUpdateWithThreadConnection() throws Exception {
  final String sql = "UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = 4";
  int rowsAffected = 33;
  given(this.statement.executeUpdate(sql)).willReturn(rowsAffected);
  given(this.connection.createStatement()).willReturn(this.statement);
  int actualRowsAffected = this.template.update(sql);
  assertTrue("Actual rows affected is correct", actualRowsAffected == rowsAffected);
  verify(this.statement).close();
  verify(this.connection).close();
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void testUpdateCount() throws Exception {
  final String sql = "UPDATE INVOICE SET DATE_DISPATCHED = SYSDATE WHERE ID = ?";
  int idParam = 11111;
  given(this.preparedStatement.executeUpdate()).willReturn(1);
  Dispatcher d = new Dispatcher(idParam, sql);
  int rowsAffected = this.template.update(d);
  assertTrue("1 update affected 1 row", rowsAffected == 1);
  verify(this.preparedStatement).setInt(1, idParam);
  verify(this.preparedStatement).close();
  verify(this.connection).close();
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void deleteWithoutWhereClause() throws Exception {
  given(jdbcTemplate.update("DELETE FROM person")).willReturn(10);
  int deleted = JdbcTestUtils.deleteFromTableWhere(jdbcTemplate, "person", null);
  assertThat(deleted, equalTo(10));
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void deleteWithWhereClauseAndArguments() throws Exception {
  given(jdbcTemplate.update("DELETE FROM person WHERE name = ? and age > ?", "Bob", 25)).willReturn(10);
  int deleted = JdbcTestUtils.deleteFromTableWhere(jdbcTemplate, "person", "name = ? and age > ?", "Bob", 25);
  assertThat(deleted, equalTo(10));
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Test update with static SQL.
 */
@Test
public void testSqlUpdate() throws Exception {
  final String sql = "UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = 4";
  int rowsAffected = 33;
  given(this.statement.executeUpdate(sql)).willReturn(rowsAffected);
  given(this.connection.createStatement()).willReturn(this.statement);
  int actualRowsAffected = this.template.update(sql);
  assertTrue("Actual rows affected is correct", actualRowsAffected == rowsAffected);
  verify(this.statement).close();
  verify(this.connection).close();
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void deleteWithWhereClause() throws Exception {
  given(jdbcTemplate.update("DELETE FROM person WHERE name = 'Bob' and age > 25")).willReturn(10);
  int deleted = JdbcTestUtils.deleteFromTableWhere(jdbcTemplate, "person", "name = 'Bob' and age > 25");
  assertThat(deleted, equalTo(10));
}

相关文章