Java Code Examples for java.sql.Statement#clearWarnings()

The following examples show how to use java.sql.Statement#clearWarnings() . 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: SqlExceptionHelper.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * General purpose handling of warnings associated with a JDBC {@link Statement}.
 *
 * @param statement The JDBC statement potentially containing warnings
 * @param handler The handler for each individual warning in the stack.
 *
 * @see #walkWarnings
 */
@SuppressWarnings({"ThrowableResultOfMethodCallIgnored"})
public void handleAndClearWarnings(
		Statement statement,
		WarningHandler handler) {
	// See HHH-9174.  Statement#getWarnings can be an expensive call for many JDBC libs.  Don't do it unless
	// the log level would actually allow a warning to be logged.
	if ( logWarnings ) {
		try {
			walkWarnings( statement.getWarnings(), handler );
		}
		catch (SQLException sqlException) {
			// workaround for WebLogic
			LOG.debug( "could not log warnings", sqlException );
		}
	}
	try {
		// Sybase fail if we don't do that, sigh...
		statement.clearWarnings();
	}
	catch (SQLException sqle) {
		LOG.debug( "could not clear warnings", sqle );
	}
}
 
Example 2
Source File: JDBCDisplayUtil.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
	Print information about the SQL warnings for the Statement
	to the given PrintWriter.
	Walks the list of exceptions, if any.

	@param out the place to write to
	@param s the Statement that may have warnings on it
 */
static public void ShowWarnings(PrintWriter out, Statement s)
{
    try {
	// GET STATEMENT WARNINGS
	SQLWarning warning = null;

	if (s != null) {
		ShowWarnings(out, s.getWarnings());
	}

	if (s != null) {
		s.clearWarnings();
	}
    } catch (SQLException e) {
		ShowSQLException(out, e);
    }
}
 
Example 3
Source File: JDBCDisplayUtil.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
static public void ShowWarnings(PrintStream out, Statement s)
{
    try {
	// GET STATEMENT WARNINGS
	SQLWarning warning = null;

	if (s != null) {
		ShowWarnings(out, s.getWarnings());
	}

	if (s != null) {
		s.clearWarnings();
	}
    } catch (SQLException e) {
		ShowSQLException(out, e);
    }
}
 
Example 4
Source File: JdbcTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private void checkStatement(Connection con, Statement statement) throws Exception {
  assertEquals(con, statement.getConnection());

  assertNull(statement.getWarnings());
  statement.clearWarnings();
  assertNull(statement.getWarnings());

  assertEquals(ResultSet.TYPE_FORWARD_ONLY, statement.getResultSetType());
  assertEquals(ResultSet.CONCUR_READ_ONLY, statement.getResultSetConcurrency());

  assertEquals(ResultSet.FETCH_FORWARD, statement.getFetchDirection());
  statement.setFetchDirection(ResultSet.FETCH_FORWARD);
  assertEquals(ResultSet.FETCH_FORWARD, statement.getFetchDirection());

  assertEquals(0, statement.getFetchSize());
  statement.setFetchSize(0);
  assertEquals(0, statement.getFetchSize());
}
 
Example 5
Source File: JDBCDisplayUtil.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
	Print information about the SQL warnings for the Statement
	to the given PrintWriter.
	Walks the list of exceptions, if any.

	@param out the place to write to
	@param s the Statement that may have warnings on it
 */
static public void ShowWarnings(PrintWriter out, Statement s)
{
    try {
	// GET STATEMENT WARNINGS
	SQLWarning warning = null;

	if (s != null) {
		ShowWarnings(out, s.getWarnings());
	}

	if (s != null) {
		s.clearWarnings();
	}
    } catch (SQLException e) {
		ShowSQLException(out, e);
    }
}
 
Example 6
Source File: JDBCDisplayUtil.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
static public void ShowWarnings(PrintStream out, Statement s)
{
    try {
	// GET STATEMENT WARNINGS
	SQLWarning warning = null;

	if (s != null) {
		ShowWarnings(out, s.getWarnings());
	}

	if (s != null) {
		s.clearWarnings();
	}
    } catch (SQLException e) {
		ShowSQLException(out, e);
    }
}
 
Example 7
Source File: SQLTools.java    From jsqsh with Apache License 2.0 6 votes vote down vote up
/**
 * Helper method available to all commands to dump any warnings
 * associated with a statement. The set of warnings is cleared
 * after display.
 * 
 * @param session The session to use for writing
 * @param statement The statement that may, or may not, contain warnings.
 */
static public void printWarnings(Session session, Statement statement) {
    
    try {
        
        SQLWarning w = statement.getWarnings();
        if (w != null) {
            
            printWarnings(session, w);
            statement.clearWarnings();
        }
    }
    catch (SQLException e) {
        
        /* IGNORED */
    }
}
 
Example 8
Source File: JDBCDisplayUtil.java    From spliceengine with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
	Print information about the SQL warnings for the Statement
	to the given PrintWriter.
	Walks the list of exceptions, if any.

	@param out the place to write to
	@param s the Statement that may have warnings on it
 */
static public void ShowWarnings(PrintWriter out, Statement s)
{
    try {
	// GET STATEMENT WARNINGS
	SQLWarning warning = null;

	if (s != null) {
		ShowWarnings(out, s.getWarnings());
	}

	if (s != null) {
		s.clearWarnings();
	}
    } catch (SQLException e) {
		ShowSQLException(out, e);
    }
}
 
Example 9
Source File: JDBCDisplayUtil.java    From spliceengine with GNU Affero General Public License v3.0 6 votes vote down vote up
static public void ShowWarnings(PrintStream out, Statement s)
{
    try {
	// GET STATEMENT WARNINGS
	SQLWarning warning = null;

	if (s != null) {
		ShowWarnings(out, s.getWarnings());
	}

	if (s != null) {
		s.clearWarnings();
	}
    } catch (SQLException e) {
		ShowSQLException(out, e);
    }
}
 
Example 10
Source File: StatementWrapper.java    From Oceanus with Apache License 2.0 5 votes vote down vote up
@Override
public void clearWarnings() throws SQLException {
	for (Statement stmt : statements) {
		stmt.clearWarnings();
	}

}
 
Example 11
Source File: StatementAdapterTest.java    From sharding-jdbc-1.5.1 with Apache License 2.0 4 votes vote down vote up
@Test
public void assertClearWarnings() throws SQLException {
    for (Statement each : statements.values()) {
        each.clearWarnings();
    }
}
 
Example 12
Source File: StatementAdapterTest.java    From shardingsphere with Apache License 2.0 4 votes vote down vote up
@Test
public void assertClearWarnings() throws SQLException {
    for (Statement each : statements.values()) {
        each.clearWarnings();
    }
}
 
Example 13
Source File: SWStatementTest.java    From skywalking with Apache License 2.0 4 votes vote down vote up
@Test
public void testPreparedStatementConfig() throws SQLException {
    Statement statement = swConnection.createStatement();
    statement.cancel();
    statement.getUpdateCount();
    statement.setFetchDirection(1);
    statement.getFetchDirection();
    statement.getResultSetConcurrency();
    statement.getResultSetType();
    statement.isClosed();
    statement.setPoolable(false);
    statement.isPoolable();
    statement.getWarnings();
    statement.clearWarnings();
    statement.setCursorName("test");
    statement.setMaxFieldSize(11);
    statement.getMaxFieldSize();
    statement.setMaxRows(10);
    statement.getMaxRows();
    statement.setEscapeProcessing(true);
    statement.setFetchSize(1);
    statement.getFetchSize();
    statement.setQueryTimeout(1);
    statement.getQueryTimeout();
    Connection connection = statement.getConnection();

    statement.execute("SELECT * FROM test");
    statement.getMoreResults();
    statement.getMoreResults(1);
    statement.getResultSetHoldability();
    statement.getResultSet();

    statement.close();
    verify(mysqlStatement).getUpdateCount();
    verify(mysqlStatement).getMoreResults();
    verify(mysqlStatement).setFetchDirection(anyInt());
    verify(mysqlStatement).getFetchDirection();
    verify(mysqlStatement).getResultSetType();
    verify(mysqlStatement).isClosed();
    verify(mysqlStatement).setPoolable(anyBoolean());
    verify(mysqlStatement).getWarnings();
    verify(mysqlStatement).clearWarnings();
    verify(mysqlStatement).setCursorName(anyString());
    verify(mysqlStatement).setMaxFieldSize(anyInt());
    verify(mysqlStatement).getMaxFieldSize();
    verify(mysqlStatement).setMaxRows(anyInt());
    verify(mysqlStatement).getMaxRows();
    verify(mysqlStatement).setEscapeProcessing(anyBoolean());
    verify(mysqlStatement).getResultSetConcurrency();
    verify(mysqlStatement).getResultSetConcurrency();
    verify(mysqlStatement).getResultSetType();
    verify(mysqlStatement).getMoreResults(anyInt());
    verify(mysqlStatement).setFetchSize(anyInt());
    verify(mysqlStatement).getFetchSize();
    verify(mysqlStatement).getQueryTimeout();
    verify(mysqlStatement).setQueryTimeout(anyInt());
    verify(mysqlStatement).getResultSet();
    assertThat(connection, CoreMatchers.<Connection>is(swConnection));

    TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
    List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
    assertThat(spans.size(), is(1));
    assertDBSpan(spans.get(0), "Mysql/JDBI/Statement/execute", "SELECT * FROM test");
}