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

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

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

JdbcTemplate.setIgnoreWarnings介绍

[英]Set whether or not we want to ignore SQLWarnings.

Default is "true", swallowing and logging all warnings. Switch this flag to "false" to make the JdbcTemplate throw a SQLWarningException instead.
[中]设置是否要忽略SQLWarnings。
默认值为“true”,接受并记录所有警告。将此标志切换为“false”,以使JdbcTemplate转而引发SQLWarningException。

代码示例

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

@Test
public void testIgnoredWarning() throws Exception {
  String sql = "SELECT forename from custmr";
  SQLWarning warnings = new SQLWarning("My warning");
  given(this.resultSet.next()).willReturn(false);
  given(this.connection.createStatement()).willReturn(this.preparedStatement);
  given(this.preparedStatement.getWarnings()).willReturn(warnings);
  // Too long: truncation
  this.template.setIgnoreWarnings(true);
  this.template.query(sql, rs -> {
    rs.getByte(1);
  });
  verify(this.resultSet).close();
  verify(this.preparedStatement).close();
  verify(this.connection).close();
}

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

/**
 * Mock objects allow us to produce warnings at will
 */
@Test
public void testFatalWarning() throws Exception {
  String sql = "SELECT forename from custmr";
  SQLWarning warnings = new SQLWarning("My warning");
  given(this.resultSet.next()).willReturn(false);
  given(this.preparedStatement.getWarnings()).willReturn(warnings);
  given(this.connection.createStatement()).willReturn(this.preparedStatement);
  JdbcTemplate t = new JdbcTemplate(this.dataSource);
  t.setIgnoreWarnings(false);
  this.thrown.expect(SQLWarningException.class);
  this.thrown.expect(exceptionCause(sameInstance(warnings)));
  try {
    t.query(sql, rs -> {
      rs.getByte(1);
    });
  }
  finally {
    verify(this.resultSet).close();
    verify(this.preparedStatement).close();
    verify(this.connection).close();
  }
}

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

@Test
public void testBeanProperties() throws Exception {
  assertTrue("datasource ok", this.template.getDataSource() == this.dataSource);
  assertTrue("ignores warnings by default", this.template.isIgnoreWarnings());
  this.template.setIgnoreWarnings(false);
  assertTrue("can set NOT to ignore warnings", !this.template.isIgnoreWarnings());
}

代码示例来源:origin: io.bufferslayer/buffer-spring-jdbc

public void setIgnoreWarnings(boolean ignoreWarnings) {
 delegate.setIgnoreWarnings(ignoreWarnings);
}

代码示例来源:origin: io.bufferslayer/bufferslayer-spring-jdbc

public void setIgnoreWarnings(boolean ignoreWarnings) {
 delegate.setIgnoreWarnings(ignoreWarnings);
}

代码示例来源:origin: fast-sql/FastSQL

/**
 * 创建一个SQL实例
 */
public SQL sql() {
  if (this.jdbcTemplate == null) {
    this.jdbcTemplate = new JdbcTemplate();
    this.jdbcTemplate.setIgnoreWarnings(ignoreWarnings);
    this.jdbcTemplate.setFetchSize(fetchSize);
    this.jdbcTemplate.setMaxRows(maxRows);
    this.jdbcTemplate.setQueryTimeout(queryTimeout);
    this.jdbcTemplate.setSkipResultsProcessing(skipResultsProcessing);
    this.jdbcTemplate.setSkipUndeclaredResults(skipUndeclaredResults);
    this.jdbcTemplate.setResultsMapCaseInsensitive(resultsMapCaseInsensitive);
    this.jdbcTemplate.setDataSource(this.dataSource);
  }
  return new SQL(this.jdbcTemplate, this.dataSourceType);
}

相关文章