List of usage examples for java.sql SQLWarning getNextWarning
public SQLWarning getNextWarning()
SQLWarning
object by setNextWarning
. From source file:org.wso2.mobile.utils.persistence.EMMDBInitializer.java
/** * executes given sql//ww w . j a v a 2s .c o m * * @param sql * @throws Exception */ private void executeSQL(String sql) throws Exception { // Check and ignore empty statements if ("".equals(sql.trim())) { return; } 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"); } Connection 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("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 Exception("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); } } } }
From source file:org.wso2.carbon.social.sql.SocialDBInitilizer.java
/** * executes given sql/* w ww .ja va2 s . c o m*/ * * @param sql * @throws Exception */ private void executeSQL(String sql) throws Exception { // Check and ignore empty statements if ("".equals(sql.trim())) { return; } 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"); } Connection 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("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 Exception("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); } } } }
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;//from w ww. j a v a2 s. c o 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.identity.core.persistence.IdentityDBInitializer.java
/** * executes given sql//from w w w . ja va 2 s .c o m * * @param sql * @throws Exception */ private void executeSQL(String sql) { // 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) { 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 IdentityRuntimeException("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.utils.dbcreator.DatabaseCreator.java
/** * executes given sql/*from w w w . j a va 2 s . com*/ * * @param sql * @throws Exception */ private void executeSQL(String sql) throws Exception { // Check and ignore empty statements if ("".equals(sql.trim())) { return; } ResultSet resultSet = null; try { if (log.isDebugEnabled()) { log.debug("SQL : " + sql); } boolean ret; int updateCount = 0, updateCountTotal = 0; ret = statement.execute(sql); updateCount = statement.getUpdateCount(); resultSet = statement.getResultSet(); do { if (!ret && 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"); } SQLWarning warning = conn.getWarnings(); while (warning != null) { 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 Exception("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); } } } }
From source file:org.wso2.carbon.dashboard.portal.core.datasource.DataBaseInitializer.java
/** * executes given sql/* w w w . j av a 2 s. c o m*/ * * @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.apache.bigtop.itest.hive.TestJdbc.java
/** * Test simple non-statement related class. setSchema is tested elsewhere because there's work * to do for that one. Similarly with getMetadata. * * @throws SQLException/*from w w w . jav a2 s . c o m*/ */ @Test public void nonStatementCalls() throws SQLException { conn.clearWarnings(); boolean isAutoCommit = conn.getAutoCommit(); LOG.debug("Auto commit is " + isAutoCommit); String catalog = conn.getCatalog(); LOG.debug("Catalog is " + catalog); String schema = conn.getSchema(); LOG.debug("Schema is " + schema); int txnIsolation = conn.getTransactionIsolation(); LOG.debug("Transaction Isolation is " + txnIsolation); SQLWarning warning = conn.getWarnings(); while (warning != null) { LOG.debug("Found a warning: " + warning.getMessage()); warning = warning.getNextWarning(); } boolean closed = conn.isClosed(); LOG.debug("Is closed? " + closed); boolean readOnly = conn.isReadOnly(); LOG.debug("Is read only?" + readOnly); // Hive doesn't support catalogs, so setting this to whatever should be fine. If we have // non-Hive systems trying to pass this setting it to a non-valid catalog name may cause // issues, so we may need to make this value configurable or something. conn.setCatalog("fred"); }
From source file:org.apache.bigtop.itest.hive.TestJdbc.java
@Test public void statement() throws SQLException { try (Statement stmt = conn.createStatement()) { stmt.cancel();/*from w w w . j a v a 2 s . co m*/ } try (Statement stmt = conn.createStatement()) { stmt.clearWarnings(); final String tableName = "bigtop_jdbc_statement_test_table"; stmt.execute("drop table if exists " + tableName); stmt.execute("create table " + tableName + " (a int, b varchar(32))"); stmt.executeUpdate("insert into " + tableName + " values (1, 'abc'), (2, 'def')"); int intrc = stmt.getUpdateCount(); LOG.debug("Update count is " + intrc); ResultSet rs = stmt.executeQuery("select * from " + tableName); while (rs.next()) { LOG.debug("Fetched " + rs.getInt(1) + "," + rs.getString(2)); } Connection localConn = stmt.getConnection(); intrc = stmt.getFetchDirection(); LOG.debug("Fetch direction is " + intrc); intrc = stmt.getFetchSize(); LOG.debug("Fetch size is " + intrc); intrc = stmt.getMaxRows(); LOG.debug("max rows is " + intrc); boolean boolrc = stmt.getMoreResults(); LOG.debug("more results is " + boolrc); intrc = stmt.getQueryTimeout(); LOG.debug("query timeout is " + intrc); stmt.execute("select * from " + tableName); rs = stmt.getResultSet(); while (rs.next()) { LOG.debug("Fetched " + rs.getInt(1) + "," + rs.getString(2)); } intrc = stmt.getResultSetType(); LOG.debug("result set type is " + intrc); SQLWarning warning = stmt.getWarnings(); while (warning != null) { LOG.debug("Found a warning: " + warning.getMessage()); warning = warning.getNextWarning(); } boolrc = stmt.isClosed(); LOG.debug("is closed " + boolrc); boolrc = stmt.isCloseOnCompletion(); LOG.debug("is close on completion " + boolrc); boolrc = stmt.isPoolable(); LOG.debug("is poolable " + boolrc); stmt.setFetchDirection(ResultSet.FETCH_FORWARD); stmt.setFetchSize(500); stmt.setMaxRows(500); } }
From source file:it.unibas.spicy.model.algebra.query.operators.sql.ExecuteSQL.java
public void executeScript(MappingTask mappingTask, AccessConfiguration accessConfiguration, String sqlScript, Reader sourceSQLScriptReader, Reader sourceInstanceSQLScriptReader, Reader targetSQLScriptReader, Reader intermediateSQLScriptReader, int scenarioNo) throws DAOException { boolean isChainingScenario = (mappingTask.getSourceProxy() instanceof ChainingDataSourceProxy); IConnectionFactory connectionFactory = null; Connection connection = null; try {//from w w w . j a va2s. co m connectionFactory = new SimpleDbConnectionFactory(); connection = connectionFactory.getConnection(accessConfiguration); ScriptRunner scriptRunner = new ScriptRunner(connection, true, true); scriptRunner.setLogWriter(null); //giannisk if (sourceSQLScriptReader != null && sourceInstanceSQLScriptReader != null && targetSQLScriptReader != null) { StringBuilder createSchemasQuery = new StringBuilder(); createSchemasQuery .append("create schema " + SpicyEngineConstants.SOURCE_SCHEMA_NAME + scenarioNo + ";\n"); createSchemasQuery .append("create schema " + SpicyEngineConstants.TARGET_SCHEMA_NAME + scenarioNo + ";\n"); //createSchemasQuery.append("create schema " + GenerateSQL.WORK_SCHEMA_NAME + ";\n"); scriptRunner.runScript(new StringReader(createSchemasQuery.toString())); Reader sourceSchemaScript = getSourceSchemaReader(); Reader targetSchemaScript = getTargetSchemaReader(); scriptRunner.runScript(sourceSchemaScript); scriptRunner.runScript(sourceSQLScriptReader); scriptRunner.runScript(sourceInstanceSQLScriptReader); scriptRunner.runScript(targetSchemaScript); scriptRunner.runScript(targetSQLScriptReader); } if (isChainingScenario) { scriptRunner.runScript( new StringReader("create schema " + GenerateSQL.INTERMEDIATE_SCHEMA_NAME + ";\n")); Reader intermediateSchemaScript = getIntermediateSchemaReader(); scriptRunner.runScript(intermediateSchemaScript); scriptRunner.runScript(intermediateSQLScriptReader); } Statement statement = connection.createStatement(); System.out.println("Starting Data Translation" + new java.util.Date()); statement.execute(sqlScript); System.out.println("Data Translation Ended with " + statement.getUpdateCount() + "\t insertions\t" + new java.util.Date()); SQLWarning warning = statement.getWarnings(); String notice = SpicyEngineConstants.PRIMARY_KEY_CONSTR_NOTICE; while (warning != null) { if (warning.getMessage().startsWith(notice)) { String tempTableName = warning.getMessage() .substring(warning.getMessage().lastIndexOf(notice) + notice.length()).trim(); pkConstraintsTableNames.add(tempTableName); } warning = warning.getNextWarning(); } ////Reader sqlReader = new StringReader(sqlScript); /////scriptRunner.runScript(sqlReader); } catch (Exception ex) { logger.error(ex); throw new DAOException(ex); } finally { connectionFactory.close(connection); try { if (sourceSQLScriptReader != null && sourceInstanceSQLScriptReader != null && targetSQLScriptReader != null) { sourceSQLScriptReader.close(); sourceInstanceSQLScriptReader.close(); targetSQLScriptReader.close(); } } catch (IOException ex) { logger.error("Unable to close readers..." + ex); } } //return loadInstance(mappingTask, accessConfiguration, scenarioNo); }
From source file:com.tesora.dve.common.DBHelper.java
public int getNumWarnings() throws SQLException { int count = 0; if (stmt != null) { SQLWarning warning = stmt.getWarnings(); while (warning != null) { // TODO: filter for our test code until SHOW is completely fixed if (!StringUtils.equalsIgnoreCase(warning.getMessage(), "SHOW WARNINGS is not supported")) { count++;//from w ww . j ava 2 s . com } warning = warning.getNextWarning(); } return count; } return 0; }