Java Code Examples for java.sql.Statement.getWarnings()

The following are Jave code examples for showing how to use getWarnings() of the java.sql.Statement class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: the-vigilantes   File: StatementRegressionTest.java   Source Code and License Vote up 6 votes
/**
 * Tests fix for BUG#10630, Statement.getWarnings() fails with NPE if
 * statement has been closed.
 */
public void testBug10630() throws Exception {
    Connection conn2 = null;
    Statement stmt2 = null;

    try {
        conn2 = getConnectionWithProps((Properties) null);
        stmt2 = conn2.createStatement();

        conn2.close();
        stmt2.getWarnings();
        fail("Should've caught an exception here");
    } catch (SQLException sqlEx) {
        assertEquals(SQLError.SQL_STATE_ILLEGAL_ARGUMENT, sqlEx.getSQLState());
    } finally {
        if (stmt2 != null) {
            stmt2.close();
        }

        if (conn2 != null) {
            conn2.close();
        }
    }
}
 
Example 2
Project: OpenVertretung   File: StatementRegressionTest.java   Source Code and License Vote up 6 votes
/**
 * Tests fix for BUG#10630, Statement.getWarnings() fails with NPE if
 * statement has been closed.
 */
public void testBug10630() throws Exception {
    Connection conn2 = null;
    Statement stmt2 = null;

    try {
        conn2 = getConnectionWithProps((Properties) null);
        stmt2 = conn2.createStatement();

        conn2.close();
        stmt2.getWarnings();
        fail("Should've caught an exception here");
    } catch (SQLException sqlEx) {
        assertEquals(SQLError.SQL_STATE_ILLEGAL_ARGUMENT, sqlEx.getSQLState());
    } finally {
        if (stmt2 != null) {
            stmt2.close();
        }

        if (conn2 != null) {
            conn2.close();
        }
    }
}
 
Example 3
Project: lams   File: JdbcTemplate.java   Source Code and License Vote up 6 votes
/**
 * Throw an SQLWarningException if we're not ignoring warnings,
 * else log the warnings (at debug level).
 * @param stmt the current JDBC statement
 * @throws SQLWarningException if not ignoring warnings
 * @see org.springframework.jdbc.SQLWarningException
 */
protected void handleWarnings(Statement stmt) throws SQLException {
	if (isIgnoreWarnings()) {
		if (logger.isDebugEnabled()) {
			SQLWarning warningToLog = stmt.getWarnings();
			while (warningToLog != null) {
				logger.debug("SQLWarning ignored: SQL state '" + warningToLog.getSQLState() + "', error code '" +
						warningToLog.getErrorCode() + "', message [" + warningToLog.getMessage() + "]");
				warningToLog = warningToLog.getNextWarning();
			}
		}
	}
	else {
		handleWarnings(stmt.getWarnings());
	}
}
 
Example 4
Project: lams   File: SchemaExport.java   Source Code and License Vote up 6 votes
private void execute(boolean script, boolean export, Writer fileOutput, Statement statement, final String sql)
		throws IOException, SQLException {
	final SqlExceptionHelper sqlExceptionHelper = new SqlExceptionHelper();

	String formatted = formatter.format( sql );
       if (delimiter != null) formatted += delimiter;
       if (script) System.out.println(formatted);
       LOG.debug(formatted);
	if ( outputFile != null ) {
		fileOutput.write( formatted + "\n" );
	}
	if ( export ) {

		statement.executeUpdate( sql );
		try {
			SQLWarning warnings = statement.getWarnings();
			if ( warnings != null) {
				sqlExceptionHelper.logAndClearWarnings( connectionHelper.getConnection() );
			}
		}
		catch( SQLException sqle ) {
               LOG.unableToLogSqlWarnings(sqle);
		}
	}

}
 
Example 5
Project: ProyectoPacientes   File: StatementRegressionTest.java   Source Code and License Vote up 6 votes
/**
 * Tests fix for BUG#10630, Statement.getWarnings() fails with NPE if
 * statement has been closed.
 */
public void testBug10630() throws Exception {
    Connection conn2 = null;
    Statement stmt2 = null;

    try {
        conn2 = getConnectionWithProps((Properties) null);
        stmt2 = conn2.createStatement();

        conn2.close();
        stmt2.getWarnings();
        fail("Should've caught an exception here");
    } catch (SQLException sqlEx) {
        assertEquals(SQLError.SQL_STATE_ILLEGAL_ARGUMENT, sqlEx.getSQLState());
    } finally {
        if (stmt2 != null) {
            stmt2.close();
        }

        if (conn2 != null) {
            conn2.close();
        }
    }
}
 
Example 6
Project: BibliotecaPS   File: StatementRegressionTest.java   Source Code and License Vote up 6 votes
/**
 * Tests fix for BUG#10630, Statement.getWarnings() fails with NPE if
 * statement has been closed.
 */
public void testBug10630() throws Exception {
    Connection conn2 = null;
    Statement stmt2 = null;

    try {
        conn2 = getConnectionWithProps((Properties) null);
        stmt2 = conn2.createStatement();

        conn2.close();
        stmt2.getWarnings();
        fail("Should've caught an exception here");
    } catch (SQLException sqlEx) {
        assertEquals(SQLError.SQL_STATE_ILLEGAL_ARGUMENT, sqlEx.getSQLState());
    } finally {
        if (stmt2 != null) {
            stmt2.close();
        }

        if (conn2 != null) {
            conn2.close();
        }
    }
}
 
Example 7
Project: sstore-soft   File: HsqlBackend.java   Source Code and License Vote up 5 votes
public void runDDL(String ddl) {
        try {
//            System.err.println("Executing " + ddl);
            Statement stmt = dbconn.createStatement();
            /*boolean success =*/ stmt.execute(ddl);
            SQLWarning warn = stmt.getWarnings();
            if (warn != null)
                sqlLog.warn(warn.getMessage());
            //LOG.info("SQL DDL execute result: " + (success ? "true" : "false"));
        } catch (SQLException e) {
            // IGNORE??? hostLog.l7dlog( Level.ERROR, LogKeys.host_Backend_RunDDLFailed.name(), new Object[] { ddl }, e);
        }

    }
 
Example 8
Project: s-store   File: HsqlBackend.java   Source Code and License Vote up 5 votes
public void runDDL(String ddl) {
        try {
//            System.err.println("Executing " + ddl);
            Statement stmt = dbconn.createStatement();
            /*boolean success =*/ stmt.execute(ddl);
            SQLWarning warn = stmt.getWarnings();
            if (warn != null)
                sqlLog.warn(warn.getMessage());
            //LOG.info("SQL DDL execute result: " + (success ? "true" : "false"));
        } catch (SQLException e) {
            // IGNORE??? hostLog.l7dlog( Level.ERROR, LogKeys.host_Backend_RunDDLFailed.name(), new Object[] { ddl }, e);
        }

    }