Example usage for java.sql Statement setEscapeProcessing

List of usage examples for java.sql Statement setEscapeProcessing

Introduction

In this page you can find the example usage for java.sql Statement setEscapeProcessing.

Prototype

void setEscapeProcessing(boolean enable) throws SQLException;

Source Link

Document

Sets escape processing on or off.

Usage

From source file:com.nridge.core.ds.rdbms.SQLConnection.java

/**
 * Executes the SQL statement (via the underlying JDBC connection).
 *
 * @param aSQLStatement SQL statement./*from   ww  w.ja v a  2s . co  m*/
 *
 * @throws NSException Catch-all exception for any SQL related issue.
 */
public void execute(String aSQLStatement) throws NSException {
    Logger appLogger = mAppMgr.getLogger(this, "execute");

    appLogger.trace(mAppMgr.LOGMSG_TRACE_ENTER);

    mSQLStatement = aSQLStatement;
    appLogger.debug(mSQLStatement);

    Statement stmtUpdate = null;
    try {
        stmtUpdate = mConnection.createStatement();
        stmtUpdate.setEscapeProcessing(mIsStatementEscapingEnabled);
        stmtUpdate.executeUpdate(mSQLStatement);
    } catch (SQLException e) {
        throw new NSException("RDBMS Statement Error: " + mSQLStatement + " : " + e.getMessage(), e);
    } finally {
        if (stmtUpdate != null) {
            try {
                stmtUpdate.close();
            } catch (SQLException ignored) {
            }
        }
    }

    appLogger.trace(mAppMgr.LOGMSG_TRACE_DEPART);
}

From source file:com.nridge.core.ds.rdbms.hsqldb.HDBSQLTable.java

/**
 * Returns a low-level JDBC <i>ResultSet</i> representation of all rows
 * fetched from the RDBMS table that match the SQL select statement
 * provided./*  w  w w  .j  a  v a 2 s . c o  m*/
 * <p>
 * <b>Note:</b> The developer is responsible for ensuring that the
 * SQL statement is properly formatted for the RDBMS vendor it will
 * be executed against.
 * </p>
 *
 * @param aSelectFromWhereStatement SQL select statement.
 *
 * @return JDBC result set instance.
 *
 * @throws NSException Catch-all exception for any SQL related issue.
 */
@Override
public ResultSet select(String aSelectFromWhereStatement) throws NSException {
    Logger appLogger = mAppMgr.getLogger(this, "select");

    appLogger.trace(mAppMgr.LOGMSG_TRACE_ENTER);

    ResultSet resultSet;
    appLogger.debug(aSelectFromWhereStatement);
    Connection jdbcConnection = mSQLConnection.getJDBCConnection();
    try {
        Statement stmtQuery = jdbcConnection.createStatement(ResultSet.TYPE_FORWARD_ONLY,
                ResultSet.CONCUR_READ_ONLY);
        stmtQuery.setEscapeProcessing(mSQLConnection.isStatementEscapingEnabled());
        mSQLConnection.setLastStatement(aSelectFromWhereStatement);
        resultSet = stmtQuery.executeQuery(aSelectFromWhereStatement);
    } catch (SQLException e) {
        throw new NSException("RDBMS Query Error: " + aSelectFromWhereStatement + " : " + e.getMessage(), e);
    }

    appLogger.trace(mAppMgr.LOGMSG_TRACE_DEPART);

    return resultSet;
}

From source file:com.nridge.core.ds.rdbms.hsqldb.HDBSQLTable.java

private void query(String aSQLStatement, DataTable aTable, int aLimit) throws NSException {
    Logger appLogger = mAppMgr.getLogger(this, "query");

    appLogger.trace(mAppMgr.LOGMSG_TRACE_ENTER);

    Statement stmtQuery = null;
    appLogger.debug(aSQLStatement);//  w  w w .  j a  va2  s .  co m
    Connection jdbcConnection = mSQLConnection.getJDBCConnection();
    try {
        stmtQuery = jdbcConnection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
        if (aLimit > 0)
            stmtQuery.setFetchSize(aLimit);
        stmtQuery.setEscapeProcessing(mSQLConnection.isStatementEscapingEnabled());
        mSQLConnection.setLastStatement(aSQLStatement);
        ResultSet resultSet = stmtQuery.executeQuery(aSQLStatement);
        while (resultSet.next())
            addTableRowFromResultSet(aTable, resultSet);
    } catch (SQLException e) {
        throw new NSException("RDBMS Query Error: " + aSQLStatement + " : " + e.getMessage(), e);
    } finally {
        if (stmtQuery != null) {
            try {
                stmtQuery.close();
            } catch (SQLException ignored) {
            }
        }
    }

    appLogger.trace(mAppMgr.LOGMSG_TRACE_DEPART);
}

From source file:com.nridge.core.ds.rdbms.hsqldb.HDBSQLTable.java

private void queryFunction(String aSQLStatement, DataTable aTable, int aLimit) throws NSException {
    Logger appLogger = mAppMgr.getLogger(this, "queryFunction");

    appLogger.trace(mAppMgr.LOGMSG_TRACE_ENTER);

    Statement stmtQuery = null;
    appLogger.debug(aSQLStatement);//from  ww w  . j  a v  a2 s  .c  om
    Connection jdbcConnection = mSQLConnection.getJDBCConnection();
    try {
        stmtQuery = jdbcConnection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
        if (aLimit > 0)
            stmtQuery.setFetchSize(aLimit);
        stmtQuery.setEscapeProcessing(mSQLConnection.isStatementEscapingEnabled());
        mSQLConnection.setLastStatement(aSQLStatement);
        ResultSet resultSet = stmtQuery.executeQuery(aSQLStatement);
        while (resultSet.next())
            addTableRowFromFunctionResultSet(aTable, resultSet);
    } catch (SQLException e) {
        throw new NSException("RDBMS Query Error: " + aSQLStatement + " : " + e.getMessage(), e);
    } finally {
        if (stmtQuery != null) {
            try {
                stmtQuery.close();
            } catch (SQLException ignored) {
            }
        }
    }

    appLogger.trace(mAppMgr.LOGMSG_TRACE_DEPART);
}

From source file:edu.ku.brc.specify.conversion.BasicSQLUtils.java

/**
 * Executes an SQL Update command//from   ww  w  .  j a v  a2s .c o  m
 * @param stmt Statement object to execute the SQL
 * @param cmdStr the SQL string to execute
 * @return the return code from the executeUpdate call
 */
public static int exeUpdateCmd(Statement stmt, String cmdStr) {

    try {
        //log.debug("---- exeUpdateCmd" + cmdStr);
        stmt.setEscapeProcessing(true);
        return stmt.executeUpdate(cmdStr);
    } catch (Exception ex) {
        //TODO: Problem encountered with the CUPaleo database when converting the AccessionAgent 
        //We (Rod?) need to go in an create a hashtable that
        if ((ex instanceof MySQLIntegrityConstraintViolationException)
                && (cmdStr.contains("INSERT INTO accessionagent"))) {
            log.error("ignoring a record because it makes a MySQLIntegrityConstraintViolation: "
                    + ex.getStackTrace().toString());
            log.error(cmdStr + "\n");
            ex.printStackTrace();
            return 0;
        } else if (cmdStr.contains("INSERT INTO accessionagent")) {
            log.error("ignoring a record because it makes a uncatchable SQL Exception: " + ex.getMessage());
            log.error("    " + cmdStr + "\n");
            //ex.printStackTrace();
            return 0;
        } else {
            //e.printStackTrace();
            log.error(ex.getMessage());
            log.error(cmdStr + "\n");
            ex.printStackTrace();
            //ex.getStackTrace().
            throw new RuntimeException(ex);
        }
    }
    //return -1;
}

From source file:org.codehaus.mojo.dbupgrade.generic.DBUpgradeUsingSQLNoParser.java

public void upgradeDB(SQLExec sqlexec, String dialect) throws DBUpgradeException {
    InputStream is = null;// w  w w  .ja v a  2s.  c  o  m
    Statement statement = null;
    String sql = null;

    try {
        is = DBUpgradeUsingSQL.class.getClassLoader().getResourceAsStream(this.sqlResouceName);
        sql = IOUtils.toString(is);

        statement = sqlexec.getConnection().createStatement();
        statement.setEscapeProcessing(false);

        if (statement.execute(sql)) {
            //we expect a false return since the execution has no result set
            throw new DBUpgradeException("Unable execute SQL Statement:" + sql);
        }

    } catch (IOException e) {
        throw new DBUpgradeException("Unable load SQL Statement from resource:" + sqlResouceName, e);
    } catch (SQLException e) {
        throw new DBUpgradeException("Unable execute SQL Statement:" + sql, e);
    } finally {
        DbUtils.closeQuietly(statement);
    }

}

From source file:org.codehaus.mojo.dbupgrade.sqlexec.DefaultSQLExec.java

public void execute(File sqlFile, boolean disableSQLParser) throws SQLException, IOException {
    if (!disableSQLParser) {
        this.execute(sqlFile);
    } else {//from   w ww  .j av  a  2s  . c  o m
        InputStream is = null;
        Statement statement = null;
        String sql = null;

        try {
            is = new FileInputStream(sqlFile);
            sql = IOUtils.toString(is);

            statement = getConnection().createStatement();
            statement.setEscapeProcessing(false);

            if (statement.execute(sql)) {
                //we expect a false return since the execution has no result set
                throw new SQLException("Unable execute SQL Statement:" + sql);
            }

        } finally {
            DbUtils.closeQuietly(statement);
            IOUtils.closeQuietly(is);
        }
    }

}

From source file:org.executequery.databasemediators.spi.DefaultStatementExecutor.java

private void setStatementEscapeProcessing(Statement statement, boolean enableEscapes) {

    try {// w ww . j ava 2s.c  om

        statement.setEscapeProcessing(enableEscapes);

    } catch (SQLException e) {

        Log.warning("Attempt to set statement escape processing failed - " + e.getMessage());
    }
}