org.springframework.jdbc.SQLWarningException Java Examples

The following examples show how to use org.springframework.jdbc.SQLWarningException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JdbcTemplateTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * 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);

	ResultSetExtractor<Byte> extractor = rs -> rs.getByte(1);
	assertThatExceptionOfType(SQLWarningException.class).isThrownBy(() ->
			t.query(sql, extractor))
		.withCause(warnings);
	verify(this.resultSet).close();
	verify(this.preparedStatement).close();
	verify(this.connection).close();
}
 
Example #2
Source File: JdbcTemplateTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * 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();
	}
}
 
Example #3
Source File: JdbcTemplateTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * 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, new RowCallbackHandler() {
			@Override
			public void processRow(ResultSet rs) throws SQLException {
				rs.getByte(1);
			}
		});
	}
	finally {
		verify(this.resultSet).close();
		verify(this.preparedStatement).close();
		verify(this.connection).close();
	}
}
 
Example #4
Source File: JdbcTemplateTests.java    From effectivejava with Apache License 2.0 5 votes vote down vote up
/**
 * 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, new RowCallbackHandler() {
			@Override
			public void processRow(ResultSet rs) throws SQLException {
				rs.getByte(1);
			}
		});
	}
	finally {
		verify(this.resultSet).close();
		verify(this.preparedStatement).close();
		verify(this.connection).close();
	}
}
 
Example #5
Source File: KratosJdbcTemplate.java    From kratos-1 with Apache License 2.0 4 votes vote down vote up
@Override
protected void handleWarnings(SQLWarning warning) throws SQLWarningException {

	super.handleWarnings(warning);
}
 
Example #6
Source File: JdbcTemplate.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Throw a SQLWarningException if encountering an actual warning.
 * @param warning the warnings object from the current statement.
 * May be {@code null}, in which case this method does nothing.
 * @throws SQLWarningException in case of an actual warning to be raised
 */
protected void handleWarnings(@Nullable SQLWarning warning) throws SQLWarningException {
	if (warning != null) {
		throw new SQLWarningException("Warning not ignored", warning);
	}
}
 
Example #7
Source File: JdbcTemplate.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * Throw an SQLWarningException if encountering an actual warning.
 * @param warning the warnings object from the current statement.
 * May be {@code null}, in which case this method does nothing.
 * @throws SQLWarningException in case of an actual warning to be raised
 */
protected void handleWarnings(@Nullable SQLWarning warning) throws SQLWarningException {
	if (warning != null) {
		throw new SQLWarningException("Warning not ignored", warning);
	}
}
 
Example #8
Source File: JdbcTemplate.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Throw an SQLWarningException if encountering an actual warning.
 * @param warning the warnings object from the current statement.
 * May be {@code null}, in which case this method does nothing.
 * @throws SQLWarningException in case of an actual warning to be raised
 */
protected void handleWarnings(SQLWarning warning) throws SQLWarningException {
	if (warning != null) {
		throw new SQLWarningException("Warning not ignored", warning);
	}
}
 
Example #9
Source File: JdbcTemplate.java    From spring4-understanding with Apache License 2.0 2 votes vote down vote up
/**
 * Throw an SQLWarningException if encountering an actual warning.
 * @param warning the warnings object from the current statement.
 * May be {@code null}, in which case this method does nothing.
 * @throws SQLWarningException in case of an actual warning to be raised
 */
protected void handleWarnings(SQLWarning warning) throws SQLWarningException {
	if (warning != null) {
		throw new SQLWarningException("Warning not ignored", warning);
	}
}
 
Example #10
Source File: JdbcTemplate.java    From effectivejava with Apache License 2.0 2 votes vote down vote up
/**
 * Throw an SQLWarningException if encountering an actual warning.
 * @param warning the warnings object from the current statement.
 * May be {@code null}, in which case this method does nothing.
 * @throws SQLWarningException in case of an actual warning to be raised
 */
protected void handleWarnings(SQLWarning warning) throws SQLWarningException {
	if (warning != null) {
		throw new SQLWarningException("Warning not ignored", warning);
	}
}