List of usage examples for java.sql Connection clearWarnings
void clearWarnings() throws SQLException;
Connection
object. From source file:org.wso2.carbon.identity.application.common.persistence.IdentityApplicationDBInitializer.java
private void executeSQL(String sql) throws SQLException { // Check and ignore empty statements if ("".equals(sql.trim())) { return;// ww w. j ava 2 s. co m } Connection conn = null; ResultSet resultSet = null; try { if (log.isDebugEnabled()) { log.debug("SQL : " + sql); } boolean ret; int updateCount, updateCountTotal = 0; ret = statement.execute(sql); updateCount = statement.getUpdateCount(); resultSet = statement.getResultSet(); do { if (!ret) { if (updateCount != -1) { updateCountTotal += updateCount; } } ret = statement.getMoreResults(); if (ret) { updateCount = statement.getUpdateCount(); resultSet = statement.getResultSet(); } } while (ret); if (log.isDebugEnabled()) { log.debug(sql + " : " + updateCountTotal + " rows affected"); } conn = dataSource.getConnection(); SQLWarning warning = conn.getWarnings(); while (warning != null) { log.debug(warning + " sql warning"); warning = warning.getNextWarning(); } conn.clearWarnings(); } catch (SQLException e) { if (e.getSQLState().equals("42710")) { // eliminating the table already exception for the derby and DB2 database types if (log.isDebugEnabled()) { log.info( "Identity Application Management database already exists. Not creating a new database"); } } else { throw e; } } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { log.error(e.getMessage(), e); } } if (conn != null) { try { conn.close(); } catch (SQLException e) { log.error(e.getMessage(), e); } } } }
From source file:org.wso2.carbon.dashboard.portal.core.datasource.DataBaseInitializer.java
/** * executes given sql//from w w w. j av a2s . c om * * @param sql Sql query to be executed * @throws DashboardPortalException */ private void executeSQL(String sql) throws DashboardPortalException { // Check and ignore empty statements if ("".equals(sql.trim())) { return; } ResultSet resultSet = null; Connection conn = null; try { if (log.isDebugEnabled()) { log.debug("SQL : " + sql); } boolean ret; int updateCount, updateCountTotal = 0; ret = statement.execute(sql); updateCount = statement.getUpdateCount(); resultSet = statement.getResultSet(); do { if (!ret) { if (updateCount != -1) { updateCountTotal += updateCount; } } ret = statement.getMoreResults(); if (ret) { updateCount = statement.getUpdateCount(); resultSet = statement.getResultSet(); } } while (ret); if (log.isDebugEnabled()) { log.debug(sql + " : " + updateCountTotal + " rows affected"); } conn = dataSource.getConnection(); SQLWarning warning = conn.getWarnings(); while (warning != null) { if (log.isDebugEnabled()) { log.debug(warning + " sql warning"); warning = warning.getNextWarning(); } } conn.clearWarnings(); } catch (SQLException e) { if (e.getSQLState().equals("X0Y32") || e.getSQLState().equals("42710")) { // eliminating the table already exception for the derby and DB2 database types if (log.isDebugEnabled()) { log.info("Table Already Exists. Hence, skipping table creation"); } } else { throw new DashboardPortalException("Error occurred while executing : " + sql, e); } } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { log.error("Error occurred while closing result set.", e); } } if (conn != null) { try { conn.close(); } catch (SQLException e) { log.error("Error occurred while closing sql connection.", e); } } } }
From source file:org.wso2.carbon.dashboard.portal.core.datasource.DSDataSourceManager.java
/** * executes given sql/*from w w w . j av a 2 s.c o m*/ * * @param sql Sql query to be executed * @throws DashboardPortalException */ private void executeQuery(String sql) throws DashboardPortalException { // Check and ignore empty statements if (sql.trim().isEmpty()) { return; } ResultSet resultSet = null; Connection conn = null; try { if (log.isDebugEnabled()) { log.debug("SQL : " + sql); } boolean ret; int updateCount, updateCountTotal = 0; ret = statement.execute(sql); updateCount = statement.getUpdateCount(); resultSet = statement.getResultSet(); do { if (!ret) { if (updateCount != -1) { updateCountTotal += updateCount; } } ret = statement.getMoreResults(); if (ret) { updateCount = statement.getUpdateCount(); resultSet = statement.getResultSet(); } } while (ret); if (log.isDebugEnabled()) { log.debug(sql + " : " + updateCountTotal + " rows affected"); } conn = dataSource.getConnection(); SQLWarning warning = conn.getWarnings(); while (warning != null) { if (log.isDebugEnabled()) { log.debug(warning + " sql warning"); warning = warning.getNextWarning(); } } conn.clearWarnings(); } catch (SQLException e) { throw new DashboardPortalException("Error occurred while executing : " + sql, e); } finally { closeDatabaseResources(conn, null, resultSet); } }
From source file:org.apache.ddlutils.platform.PlatformImplBase.java
/** * {@inheritDoc}/*from w ww .ja v a 2 s. c om*/ */ public int evaluateBatch(Connection connection, String sql, boolean continueOnError) throws DatabaseOperationException { Statement statement = null; int errors = 0; int commandCount = 0; // we tokenize the SQL along the delimiters, and we also make sure that only delimiters // at the end of a line or the end of the string are used (row mode) try { statement = connection.createStatement(); SqlTokenizer tokenizer = new SqlTokenizer(sql); while (tokenizer.hasMoreStatements()) { String command = tokenizer.getNextStatement(); // ignore whitespace command = command.trim(); if (command.length() == 0) { continue; } commandCount++; if (_log.isDebugEnabled()) { _log.debug("About to execute SQL " + command); } try { int results = statement.executeUpdate(command); if (_log.isDebugEnabled()) { _log.debug("After execution, " + results + " row(s) have been changed"); } } catch (SQLException ex) { if (continueOnError) { // Since the user deciced to ignore this error, we log the error // on level warn, and the exception itself on level debug _log.warn("SQL Command " + command + " failed with: " + ex.getMessage()); if (_log.isDebugEnabled()) { _log.debug(ex); } errors++; } else { throw new DatabaseOperationException("Error while executing SQL " + command, ex); } } // lets display any warnings SQLWarning warning = connection.getWarnings(); while (warning != null) { _log.warn(warning.toString()); warning = warning.getNextWarning(); } connection.clearWarnings(); } _log.info("Executed " + commandCount + " SQL command(s) with " + errors + " error(s)"); } catch (SQLException ex) { throw new DatabaseOperationException("Error while executing SQL", ex); } finally { closeStatement(statement); } return errors; }