Java Code Examples for org.springframework.jdbc.SQLWarningException

The following examples show how to use org.springframework.jdbc.SQLWarningException. These examples are extracted from open source projects. 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 Project: spring-analysis-note   Source File: JdbcTemplateTests.java    License: 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 Project: java-technology-stack   Source File: JdbcTemplateTests.java    License: 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 Project: spring4-understanding   Source File: JdbcTemplateTests.java    License: 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 Project: effectivejava   Source File: JdbcTemplateTests.java    License: 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 Project: kratos-1   Source File: KratosJdbcTemplate.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected void handleWarnings(SQLWarning warning) throws SQLWarningException {

	super.handleWarnings(warning);
}
 
Example 6
Source Project: spring-analysis-note   Source File: JdbcTemplate.java    License: 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 Project: java-technology-stack   Source File: JdbcTemplate.java    License: 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 Project: lams   Source File: JdbcTemplate.java    License: 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 Project: spring4-understanding   Source File: JdbcTemplate.java    License: 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 Project: effectivejava   Source File: JdbcTemplate.java    License: 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);
	}
}