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

/**
 * Set the owner of the Alert Definition.
 *
 * @param rec_ The Alert Definition with the new creator already set.
 */// ww w. j a v  a2s .co  m
public void setOwner(AlertRec rec_) {
    // Ensure data is clean.
    rec_.setDependancies();

    // Update creator in database.
    String update = "update sbrext.sn_alert_view_ext set created_by = ?, modified_by = ? where al_idseq = ?";
    PreparedStatement pstmt = null;
    try {
        pstmt = _conn.prepareStatement(update);
        pstmt.setString(1, rec_.getCreator());
        pstmt.setString(2, _user);
        pstmt.setString(3, rec_.getAlertRecNum());
        pstmt.executeUpdate();
    } catch (SQLException ex) {
        // Ooops...
        int errorCode = ex.getErrorCode();
        String errorMsg = errorCode + ": " + update + "\n\n" + ex.toString();
        _logger.error(errorMsg);
    } finally {
        closeCursors(pstmt, null);
    }
}

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 w  w  w . j  a v a2 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.</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. This pattern is handled by this
 * method argument list.</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.
 * @param vals_
 *        The additional values used by an "in" clause.
 * @return 0 if successful, otherwise the database error code.
 */
private ACData[] selectAC(String select_, Timestamp start_, Timestamp end_, int pairs_, String vals_[]) {
    // Expand the "in" clause.
    int loop = pairs_ / 2;
    String markers = expandMarkers(vals_.length);

    String parts[] = select_.split("\\?");
    int pos = 0;
    String select = parts[pos++];
    for (int cnt = 0; cnt < loop; ++cnt) {
        select = select + markers + parts[pos++];
        for (int ndx = 0; ndx < 2; ++ndx) {
            select = select + "?" + parts[pos++] + "?" + parts[pos++];
        }
    }

    PreparedStatement pstmt = null;
    ResultSet rs = null;
    ACData[] list = null;
    try {
        pstmt = _conn.prepareStatement(select);
        int arg = 1;
        for (int cnt = 0; cnt < loop; ++cnt) {
            for (int ndx = 0; ndx < vals_.length; ++ndx) {
                pstmt.setString(arg++, vals_[ndx]);
            }
            for (int ndx = 0; ndx < 2; ++ndx) {
                pstmt.setTimestamp(arg++, start_);
                pstmt.setTimestamp(arg++, 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

/**
 * Look for an Alert owned by the user with a Query which
 * references the id specified.//from  w  w w  .j  a  v  a 2 s. c o m
 *
 * @param id_ The Context, Form, CS, etc ID_SEQ value.
 * @param user_ The user who should own the Alert if it exists.
 * @return true if the user already watches the id, otherwise false.
 */
public String checkQuery(String id_, String user_) {
    String select = "select al.name " + "from sbrext.sn_alert_view_ext al, sbrext.sn_query_view_ext qur "
            + "where al.created_by = ? and qur.al_idseq = al.al_idseq and qur.value = ?";

    String rc = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        pstmt = _conn.prepareStatement(select);
        pstmt.setString(1, user_);
        pstmt.setString(2, id_);
        rs = pstmt.executeQuery();
        if (rs.next())
            rc = rs.getString(1);
    } catch (SQLException ex) {
        // Ooops...
        int errorCode = ex.getErrorCode();
        String errorMsg = errorCode + ": " + select + "\n\n" + ex.toString();
        _logger.error(errorMsg);
    } finally {
        closeCursors(pstmt, rs);
    }

    return rc;
}

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

/**
 * Select the dependant data. This method does not test the length of the
 * array (ids_) and therefore should only be called when 1000 ids or less
 * are needed.//from  ww  w.  jav  a2  s  .co m
 *
 * @param select_
 *        The SQL containing the "in" clause.
 * @param ids_
 *        The id values to be bound.
 * @return The result of the query.
 */
private ACData[] selectAC2(String select_, ACData ids_[]) {
    String markers = expandMarkers(ids_.length);

    // Split the string based on "?" markers.
    String parts[] = select_.split("\\?");
    String select = null;
    if (parts.length == 2) {
        select = parts[0] + markers + parts[1];
    } else if (parts.length == 3) {
        select = parts[0] + markers + parts[1] + markers + parts[2];
    } else {
        // Only needed during development.
        _logger.error("DEVELOPMENT ERROR 1: ==>\n" + select_ + "\n<== unexpected SQL form.");
        return null;
    }

    ACData[] list = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        // Build, bind and execute the statement.
        pstmt = _conn.prepareStatement(select);

        int cnt = 1;
        for (int ndx = 0; ndx < ids_.length; ++ndx) {
            pstmt.setString(cnt++, ids_[ndx].getIDseq());
        }
        if (parts.length == 3) {
            for (int ndx = 0; ndx < ids_.length; ++ndx) {
                pstmt.setString(cnt++, ids_[ndx].getIDseq());
            }
        }

        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  w  w w.  j a va  2s. c om*/
 * <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.</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. This pattern is
 * handled by this method argument list.</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.
 * @param vals1_
 *        The additional values used by an "in" clause.
 * @param vals2_
 *        The additional values used by a second "in" clause.
 * @return 0 if successful, otherwise the database error code.
 */
private ACData[] selectAC(String select_, Timestamp start_, Timestamp end_, int pairs_, String vals1_[],
        String vals2_[]) {
    // Expand the "in" clauses.
    String parts[] = select_.split("\\?");
    int loop = pairs_ / 2;

    String markers1 = expandMarkers(vals1_.length);
    String markers2 = expandMarkers(vals2_.length);
    int pos = 0;
    String select = parts[pos++];

    for (int cnt = 0; cnt < loop; ++cnt) {
        select = select + markers1 + parts[pos++] + markers2 + parts[pos++];
        for (int ndx = 0; ndx < 2; ++ndx) {
            select = select + "?" + parts[pos++] + "?" + parts[pos++];
        }
    }

    PreparedStatement pstmt = null;
    ResultSet rs = null;
    ACData[] list = null;
    try {
        pstmt = _conn.prepareStatement(select);
        int arg = 1;
        for (int cnt = 0; cnt < loop; ++cnt) {
            for (int ndx = 0; ndx < vals1_.length; ++ndx) {
                pstmt.setString(arg++, vals1_[ndx]);
            }
            for (int ndx = 0; ndx < vals2_.length; ++ndx) {
                pstmt.setString(arg++, vals2_[ndx]);
            }
            for (int ndx = 0; ndx < 2; ++ndx) {
                pstmt.setTimestamp(arg++, start_);
                pstmt.setTimestamp(arg++, 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

/**
 * Retrieve the CDE Browser URL if available.
 *
 * @return The URL string.//from  w  w w.j  ava2 s  . c  om
 */
public String selectBrowserURL() {
    String select = "select value from sbrext.tool_options_view_ext "
            + "where tool_name = 'CDEBrowser' and property = 'URL'";

    String rc = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;

    try {
        pstmt = _conn.prepareStatement(select);
        rs = pstmt.executeQuery();
        if (rs.next())
            rc = rs.getString(1);
    } catch (SQLException ex) {
        // Ooops...
        _errorCode = DBAlertUtil.getSQLErrorCode(ex);
        _errorMsg = _errorCode + ": " + select + "\n\n" + ex.toString();
        _logger.error(_errorMsg);
    } finally {
        closeCursors(pstmt, rs);
    }

    return rc;
}

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

/**
 * Retrieve the Report Threshold/*from www .  j a va 2  s .c  om*/
 *
 * @return The number of rows to allow in a report.
 */
public int selectReportThreshold() {
    String select = "select value from sbrext.tool_options_view_ext "
            + "where tool_name = 'SENTINEL' and property = 'REPORT.THRESHOLD.LIMIT'";

    int rc = 100;

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

    return rc;
}

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

/**
 * Get the type of the AC id from the database.
 * @param id_ The AC id./*from   ww w .  ja va  2s .c om*/
 * @return The [0] is the type and the [1] is the name of the AC.
 */
public String[] getACtype(String id_) {
    String out[] = new String[2];
    String select = "select 'conte', name from sbr.contexts_view where conte_idseq = ? " + "union "
            + "select 'cs', long_name from sbr.classification_schemes_view where cs_idseq = ? " + "union "
            + "select 'csi', long_name from sbr.cs_items_view where csi_idseq = ? " + "union "
            + "select 'qc', long_name from sbrext.quest_contents_view_ext where qc_idseq = ? and qtl_name in ('TEMPLATE','CRF') "
            + "union " + "select 'proto', long_name from sbrext.protocols_view_ext where proto_idseq = ?";

    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        pstmt = _conn.prepareStatement(select);
        pstmt.setString(1, id_);
        pstmt.setString(2, id_);
        pstmt.setString(3, id_);
        pstmt.setString(4, id_);
        pstmt.setString(5, id_);
        rs = pstmt.executeQuery();
        if (rs.next()) {
            out[0] = rs.getString(1);
            out[1] = rs.getString(2);
        } else {
            out[0] = null;
            out[1] = null;
        }
    } catch (SQLException ex) {
        // Ooops...
        int errorCode = ex.getErrorCode();
        String errorMsg = errorCode + ": " + select + "\n\n" + ex.toString();
        _logger.error(errorMsg);
    } finally {
        closeCursors(pstmt, rs);
    }
    return out;
}

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

/**
 * Do a basic search with a single column result.
 *
 * @param select_ the SQL select/*from  w w  w  .j a va2s.c  om*/
 * @return the array of results
 */
private String[] getBasicData0(String select_) {
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    String[] list = null;

    try {
        // Prepare the statement.
        pstmt = _conn.prepareStatement(select_);

        // Get the list.
        rs = pstmt.executeQuery();
        Vector<String> data = new Vector<String>();
        while (rs.next()) {
            data.add(rs.getString(1));
        }

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

    return (list != null && list.length > 0) ? list : null;
}

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

/**
 * Get the CDE Browser Url/*from   w w  w. j a va2s  .  c  o m*/
 * 
 * @param conn_ an existing database connection
 * @return the URL
 */
public String getCdeBrowserUrl(Connection conn_) {
    String url = null;
    String select = "select value from sbrext.tool_options_view_ext "
            + "where tool_name = 'CDEBrowser' and property = 'URL'";

    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        pstmt = conn_.prepareStatement(select);
        rs = pstmt.executeQuery();
        if (rs.next()) {
            url = rs.getString(1);
            if (url == null || url.length() == 0)
                url = null;
        }
    } catch (SQLException ex) {
        // Ooops...
        int errorCode = ex.getErrorCode();
        String errorMsg = errorCode + ": " + select + "\n\n" + ex.toString();
        _logger.error(errorMsg);
    } finally {
        if (rs != null) {
            try {
                rs.close();
            } catch (Exception ex) {
            }
        }
        if (pstmt != null) {
            try {
                pstmt.close();
            } catch (Exception ex) {
            }
        }
    }

    return url;
}