Example usage for java.sql SQLException toString

List of usage examples for java.sql SQLException toString

Introduction

In this page you can find the example usage for java.sql SQLException toString.

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:gov.nih.nci.cadsr.sentinel.database.DBAlertOracle.java

/**
 * Open a single simple connection to the database. No pooling is necessary.
 *
 * @param dsurl_//w  w w  .j a  v  a  2 s  .  c  om
 *        The Oracle TNSNAME entry describing the database location.
 * @param user_
 *        The ORACLE user id.
 * @param pswd_
 *        The password which must match 'user_'.
 * @return The database error code.
 */
public int open(String dsurl_, String user_, String pswd_) {
    // If we already have a connection, don't bother.
    if (_conn != null)
        return 0;

    try {
        OracleDataSource ods = new OracleDataSource();
        if (dsurl_.indexOf(':') > 0) {
            String parts[] = dsurl_.split("[:]");
            ods.setDriverType("thin");
            ods.setServerName(parts[0]);
            ods.setPortNumber(Integer.parseInt(parts[1]));
            ods.setServiceName(parts[2]);
        } else {
            ods.setDriverType("oci8");
            ods.setTNSEntryName(dsurl_);
        }
        _user = user_;
        _conn = ods.getConnection(user_, pswd_);
        _conn.setAutoCommit(false);
        _needCommit = false;
        return 0;
    } catch (SQLException ex) {
        _errorCode = DBAlertUtil.getSQLErrorCode(ex);
        _errorMsg = _errorCode + ": " + ex.toString();
        _logger.error(_errorMsg);
        return _errorCode;
    }
}

From source file:gov.nih.nci.cadsr.sentinel.database.DBAlertOracle.java

private ACData[] selectAC(String select_) {
    PreparedStatement pstmt = null;
    ResultSet rs = null;/*from   w  w w . j  a va 2s .  c  o m*/
    ACData[] list = null;
    try {
        pstmt = _conn.prepareStatement(select_);
        rs = pstmt.executeQuery();
        list = copyResults(rs);
    } catch (SQLException ex) {
        _errorCode = DBAlertUtil.getSQLErrorCode(ex);
        _errorMsg = _errorCode + ": " + select_ + "\n\n" + ex.toString();
        _logger.error(_errorMsg);
    } finally {
        closeCursors(pstmt, rs);
    }
    return list;
}

From source file:gov.nih.nci.cadsr.sentinel.database.DBAlertOracle.java

/**
 * Pull rows changed in the date range specified. There are 3 different
 * patterns to handle://from  ww  w . ja va2 s.  co  m
 * <p>
 * <ul>
 * <li>[from/to, from/to] {2, 4} - This represents the from/to date pair
 * which may occur 2 or 4 times in the SQL. This pattern is handled by this
 * method argument list.</li>
 * <li>[in, from/to, from/to] {2, 4} - This represents a single "in" clause
 * of creators or modifiers followed by the from/to pair which may occur 2
 * or 4 times in the SQL in this order.</li>
 * <li>[in, in, from/to, from/to] {2,4} - This represents an "in" clause
 * for the creators and an "in" clause for the modifiers followed by the
 * from/to pair which in total may appear 1 or 2 times.</li>
 * </ul>
 * </p>
 *
 * @param select_
 *        The SQL select for the specific data and table.
 * @param start_
 *        The date to start.
 * @param end_
 *        The date to end.
 * @param pairs_
 *        The number of pairs of (start, end) that appear in the SQL.
 * @return 0 if successful, otherwise the database error code.
 */
private ACData[] selectAC(String select_, Timestamp start_, Timestamp end_, int pairs_) {
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    ACData[] list = null;
    try {
        pstmt = _conn.prepareStatement(select_);
        for (int ndx = 0; ndx < pairs_; ++ndx) {
            pstmt.setTimestamp((ndx * 2) + 1, start_);
            pstmt.setTimestamp((ndx * 2) + 2, end_);
        }

        rs = pstmt.executeQuery();
        list = copyResults(rs);
    } catch (SQLException ex) {
        _errorCode = DBAlertUtil.getSQLErrorCode(ex);
        _errorMsg = _errorCode + ": " + select_ + "\n\n" + ex.toString();
        _logger.error(_errorMsg);
    } finally {
        closeCursors(pstmt, rs);
    }
    return list;
}

From source file:gov.nih.nci.cadsr.sentinel.database.DBAlertOracle.java

/**
 * Update the Auto Run or Manual Run timestamp.
 *
 * @param id_//from  w w w .ja v a 2s  . c o  m
 *        The alert id to update.
 * @param stamp_
 *        The new time.
 * @param run_
 *        true to update the auto run time, false to update the manual run
 *        time
 * @param setInactive_
 *        true to set the alert status to inactive, false to leave the
 *        status unchanged
 * @return 0 if successful, otherwise the database error code.
 */
public int updateRun(String id_, Timestamp stamp_, boolean run_, boolean setInactive_) {
    String update = "update sbrext.sn_alert_view_ext set " + ((run_) ? "last_auto_run" : "last_manual_run")
            + " = ?," + ((setInactive_) ? " al_status = 'I', " : "") + "modified_by = ? where al_idseq = ?";
    PreparedStatement pstmt = null;
    int rc = 0;
    try {
        // Set all the SQL arguments.
        pstmt = _conn.prepareStatement(update);
        pstmt.setTimestamp(1, stamp_);
        pstmt.setString(2, _user);
        pstmt.setString(3, id_);
        pstmt.executeUpdate();
        _needCommit = true;
    } catch (SQLException ex) {
        _errorCode = DBAlertUtil.getSQLErrorCode(ex);
        _errorMsg = _errorCode + ": " + update + "\n\n" + ex.toString();
        _logger.error(_errorMsg);
        rc = _errorCode;
    } finally {
        closeCursors(pstmt, null);
    }
    return rc;
}

From source file:gov.nih.nci.cadsr.sentinel.database.DBAlertOracle.java

/**
 * Given the id for a user, retrieve the email address.
 *
 * @param user_// w  w w  . ja v a  2s  .  com
 *        The user id.
 * @return The array of user ids with write access.
 */
public String selectEmailFromUser(String user_) {
    String select = "select ua.electronic_mail_address " + "from sbr.user_accounts_view ua "
            + "where ua.ua_name = ?";

    PreparedStatement pstmt = null;
    ResultSet rs = null;
    String temp = null;
    try {
        pstmt = _conn.prepareStatement(select);
        pstmt.setString(1, user_);
        rs = pstmt.executeQuery();
        if (rs.next()) {
            temp = rs.getString(1);
        }
    } catch (SQLException ex) {
        _errorCode = DBAlertUtil.getSQLErrorCode(ex);
        _errorMsg = _errorCode + ": " + select + "\n\n" + ex.toString();
        _logger.error(_errorMsg);
    } finally {
        closeCursors(pstmt, rs);
    }

    return temp;
}

From source file:gov.nih.nci.cadsr.sentinel.database.DBAlertOracle.java

/**
 * Retrieve the row counts for all the tables used by the Alert Report.
 * The values may be indexed using the _ACTYPE_* variables and an index
 * of _ACTYPE_LENGTH is the count of the change history table.
 *
 * @return The numbers for each table.//from  www .  j a va  2s  .c  o  m
 */
public String[] reportRowCounts() {
    String[] extraTables = { "sbrext.ac_change_history_ext", "sbrext.gs_tokens", "sbrext.gs_composite" };
    String[] extraNames = { "History Table", "Freestyle Token Index", "Freestyle Concatenation Index" };
    int total = _DBMAP3.length + extraTables.length;
    String counts[] = new String[total];

    String select = "select count(*) from ";
    String table;
    String name;

    int extraNdx = 0;
    for (int ndx = 0; ndx < counts.length; ++ndx) {
        if (ndx >= _DBMAP3.length) {
            table = extraTables[extraNdx];
            name = extraNames[extraNdx];
            ++extraNdx;
        } else if (_DBMAP3[ndx]._table == null) {
            counts[ndx] = null;
            continue;
        } else {
            table = _DBMAP3[ndx]._table;
            name = _DBMAP3[ndx]._val;
        }

        String temp = select + table;
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        try {
            pstmt = _conn.prepareStatement(temp);
            rs = pstmt.executeQuery();
            if (rs.next()) {
                counts[ndx] = name + AuditReport._ColSeparator + formatInt(rs.getString(1));
            }
        } catch (SQLException ex) {
            _errorCode = DBAlertUtil.getSQLErrorCode(ex);
            _errorMsg = temp + "\n" + ex.toString();
            counts[ndx] = name + ": " + _errorMsg;
        } finally {
            closeCursors(pstmt, rs);
        }
    }

    return counts;
}

From source file:gov.nih.nci.cadsr.sentinel.database.DBAlertOracle.java

/**
 * Insert a DE, DEC or VD into the user reserved CSI to be monitored.
 *
 * @param idseq_ the database id of the AC to be monitored.
 * @param user_ the user id for the reserved CSI
 * @return the id of the CSI if successful, null if a problem.
 *//*from   w w w  .  j a  va 2s.  c o  m*/
public String insertAC(String idseq_, String user_) {
    String user = user_.toUpperCase();

    CallableStatement stmt = null;
    String csi = null;
    try {
        stmt = _conn.prepareCall("begin SBREXT_CDE_CURATOR_PKG.ADD_TO_SENTINEL_CS(?,?,?); end;");
        stmt.registerOutParameter(3, java.sql.Types.VARCHAR);
        stmt.setString(2, user);
        stmt.setString(1, idseq_);
        stmt.execute();
        csi = stmt.getString(3);
        _needCommit = true;
    } catch (SQLException ex) {
        // Ooops...
        _errorCode = DBAlertUtil.getSQLErrorCode(ex);
        _errorMsg = _errorCode + ": " + ex.toString();
        _logger.error(_errorMsg);
    } finally {
        closeCursors(stmt, null);
    }

    return csi;
}

From source file:gov.nih.nci.cadsr.sentinel.database.DBAlertOracle.java

/**
 * Retrieve all the context id's for which a specific user has write
 * permission./*from   w  ww .j ava2 s.c  o  m*/
 *
 * @param user_
 *        The user id as stored in user_accounts_view.ua_name.
 * @return The array of context id values.
 */
public String[] selectContexts(String user_) {
    String select = "select cv.conte_idseq " + "from sbr.contexts_view cv, sbrext.user_contexts_view ucv "
            + "where ucv.ua_name = ? and ucv.privilege = 'W' and ucv.name not in ('TEST','Test','TRAINING','Training') and cv.name = ucv.name";

    PreparedStatement pstmt = null;
    ResultSet rs = null;
    String[] temp = null;
    try {
        pstmt = _conn.prepareStatement(select);
        pstmt.setString(1, user_);
        rs = pstmt.executeQuery();
        Vector<String> list = new Vector<String>();
        while (rs.next()) {
            list.add(rs.getString(1));
        }

        temp = new String[list.size()];
        for (int ndx = 0; ndx < temp.length; ++ndx) {
            temp[ndx] = (String) list.get(ndx);
        }
    } catch (SQLException ex) {
        _errorCode = DBAlertUtil.getSQLErrorCode(ex);
        _errorMsg = _errorCode + ": " + select + "\n\n" + ex.toString();
        _logger.error(_errorMsg);
    } finally {
        closeCursors(pstmt, rs);
    }

    return temp;
}

From source file:gov.nih.nci.cadsr.sentinel.database.DBAlertOracle.java

/**
 * Given the idseq of a Context, retrieve all the users with write access to
 * that context./*from   w  ww  .  j  a  v a 2  s . c om*/
 *
 * @param conte_
 *        The context idseq.
 * @return The array of user ids with write access.
 */
public String[] selectEmailsFromConte(String conte_) {
    String select = "select ua.electronic_mail_address "
            + "from sbrext.user_contexts_view uc, sbr.user_accounts_view ua, sbr.contexts_view c "
            + "where c.conte_idseq = ? and uc.name = c.name and uc.privilege = 'W' and ua.ua_name = uc.ua_name "
            + "and ua.alert_ind = 'Yes'";

    PreparedStatement pstmt = null;
    ResultSet rs = null;
    String[] curators = null;
    try {
        pstmt = _conn.prepareStatement(select);
        if (conte_.charAt(0) == '/')
            pstmt.setString(1, conte_.substring(1));
        else
            pstmt.setString(1, conte_);
        rs = pstmt.executeQuery();
        Vector<String> temp = new Vector<String>();
        while (rs.next()) {
            temp.add(rs.getString(1));
        }

        curators = new String[temp.size()];
        for (int ndx = 0; ndx < curators.length; ++ndx)
            curators[ndx] = (String) temp.get(ndx);
    } catch (SQLException ex) {
        _errorCode = DBAlertUtil.getSQLErrorCode(ex);
        _errorMsg = _errorCode + ": " + select + "\n\n" + ex.toString();
        _logger.error(_errorMsg);
    } finally {
        closeCursors(pstmt, rs);
    }

    return curators;
}

From source file:gov.nih.nci.cadsr.sentinel.database.DBAlertOracle.java

private int selectChangedTableType(String idseq_) {
    String select = "select changed_table from sbrext.ac_change_history_ext "
            + "where changed_table_idseq = ? and rownum < 2";
    int itype = -1;

    PreparedStatement pstmt = null;
    ResultSet rs = null;/*w w  w  .  j a  v  a2s.c  o  m*/
    try {
        pstmt = _conn.prepareStatement(select);
        pstmt.setString(1, idseq_);
        rs = pstmt.executeQuery();
        if (rs.next()) {
            String stype = rs.getString(1);

            if (stype.equals("CLASSIFICATION_SCHEMES"))
                itype = _ACTYPE_CS;
            else if (stype.equals("DATA_ELEMENTS"))
                itype = _ACTYPE_DE;
            else if (stype.equals("DATA_ELEMENT_CONCEPTS"))
                itype = _ACTYPE_DEC;
            else if (stype.equals("OBJECT_CLASSES_EXT"))
                itype = _ACTYPE_OC;
            else if (stype.equals("PROPERTIES_EXT"))
                itype = _ACTYPE_PROP;
            else if (stype.equals("VALUE_DOMAINS"))
                itype = _ACTYPE_VD;
        }
    } catch (SQLException ex) {
        _errorCode = DBAlertUtil.getSQLErrorCode(ex);
        _errorMsg = _errorCode + ": " + select + "\n\n" + ex.toString();
        _logger.error(_errorMsg);
    } finally {
        closeCursors(pstmt, rs);
    }
    return itype;
}