Search in sources :

Example 26 with DatabaseException

use of org.parosproxy.paros.db.DatabaseException in project zaproxy by zaproxy.

the class ParosTableAlert method reconnect.

@Override
protected void reconnect(Connection conn) throws DatabaseException {
    try {
        // ZAP: Changed to call the method updateTable(Connection).
        updateTable(conn);
        psRead = conn.prepareStatement("SELECT TOP 1 * FROM " + TABLE_NAME + " WHERE " + ALERTID + " = ?");
        psInsert = conn.prepareStatement("INSERT INTO " + TABLE_NAME + " (" + SCANID + "," + PLUGINID + "," + ALERT + "," + RISK + "," + RELIABILITY + "," + DESCRIPTION + "," + URI + "," + PARAM + "," + ATTACK + "," + OTHERINFO + "," + SOLUTION + "," + REFERENCE + "," + EVIDENCE + "," + CWEID + "," + WASCID + "," + HISTORYID + "," + SOURCEHISTORYID + "," + SOURCEID + ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
        psGetIdLastInsert = conn.prepareCall("CALL IDENTITY();");
        psDeleteAlert = conn.prepareStatement("DELETE FROM " + TABLE_NAME + " WHERE " + ALERTID + " = ?");
        psDeleteAllAlerts = conn.prepareStatement("DELETE FROM " + TABLE_NAME);
        //psDeleteScan = conn.prepareStatement("DELETE FROM ALERT WHERE " + SCANID + " = ?");
        // ZAP: New prepared statement for updating an alert
        psUpdate = conn.prepareStatement("UPDATE " + TABLE_NAME + " SET " + ALERT + " = ?, " + RISK + " = ?," + RELIABILITY + " = ?," + DESCRIPTION + " = ?," + URI + " = ?," + PARAM + " = ?," + ATTACK + " = ?," + OTHERINFO + " = ?," + SOLUTION + " = ?," + REFERENCE + " = ?, " + EVIDENCE + " = ?, " + CWEID + " = ?, " + WASCID + " = ?, " + SOURCEHISTORYID + " = ? " + "WHERE " + ALERTID + " = ?");
        psUpdateHistoryIds = conn.prepareStatement("UPDATE " + TABLE_NAME + " SET " + HISTORYID + " = ?, " + SOURCEHISTORYID + " = ? " + "WHERE " + ALERTID + " = ?");
        psGetAlertsForHistoryId = conn.prepareStatement("SELECT * FROM " + TABLE_NAME + " WHERE " + SOURCEHISTORYID + " = ?");
    } catch (SQLException e) {
        throw new DatabaseException(e);
    }
}
Also used : SQLException(java.sql.SQLException) DatabaseException(org.parosproxy.paros.db.DatabaseException)

Example 27 with DatabaseException

use of org.parosproxy.paros.db.DatabaseException in project zaproxy by zaproxy.

the class ParosTableAlert method deleteAlert.

/* (non-Javadoc)
	 * @see org.parosproxy.paros.db.paros.TableAlert#deleteAlert(int)
	 */
@Override
public synchronized void deleteAlert(int alertId) throws DatabaseException {
    try {
        psDeleteAlert.setInt(1, alertId);
        psDeleteAlert.execute();
    } catch (SQLException e) {
        throw new DatabaseException(e);
    }
}
Also used : SQLException(java.sql.SQLException) DatabaseException(org.parosproxy.paros.db.DatabaseException)

Example 28 with DatabaseException

use of org.parosproxy.paros.db.DatabaseException in project zaproxy by zaproxy.

the class ParosTableContext method deleteAllDataForContext.

/* (non-Javadoc)
	 * @see org.parosproxy.paros.db.paros.TableContext#deleteAllDataForContext(int)
	 */
@Override
public synchronized void deleteAllDataForContext(int contextId) throws DatabaseException {
    try {
        psDeleteAllDataForContext.setInt(1, contextId);
        psDeleteAllDataForContext.executeUpdate();
    } catch (SQLException e) {
        throw new DatabaseException(e);
    }
}
Also used : SQLException(java.sql.SQLException) DatabaseException(org.parosproxy.paros.db.DatabaseException)

Example 29 with DatabaseException

use of org.parosproxy.paros.db.DatabaseException in project zaproxy by zaproxy.

the class ParosTableContext method insert.

/* (non-Javadoc)
	 * @see org.parosproxy.paros.db.paros.TableContext#insert(int, int, java.lang.String)
	 */
@Override
public synchronized RecordContext insert(int contextId, int type, String url) throws DatabaseException {
    try {
        psInsert.setInt(1, contextId);
        psInsert.setInt(2, type);
        psInsert.setString(3, url);
        psInsert.executeUpdate();
        long id;
        try (ResultSet rs = psGetIdLastInsert.executeQuery()) {
            rs.next();
            id = rs.getLong(1);
        }
        return read(id);
    } catch (SQLException e) {
        throw new DatabaseException(e);
    }
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) DatabaseException(org.parosproxy.paros.db.DatabaseException)

Example 30 with DatabaseException

use of org.parosproxy.paros.db.DatabaseException in project zaproxy by zaproxy.

the class ParosTableContext method getDataForContextAndType.

/* (non-Javadoc)
	 * @see org.parosproxy.paros.db.paros.TableContext#getDataForContextAndType(int, int)
	 */
@Override
public synchronized List<RecordContext> getDataForContextAndType(int contextId, int type) throws DatabaseException {
    try {
        List<RecordContext> result = new ArrayList<>();
        psGetAllDataForContextAndType.setInt(1, contextId);
        psGetAllDataForContextAndType.setInt(2, type);
        try (ResultSet rs = psGetAllDataForContextAndType.executeQuery()) {
            while (rs.next()) {
                result.add(new RecordContext(rs.getLong(DATAID), rs.getInt(CONTEXTID), rs.getInt(TYPE), rs.getString(DATA)));
            }
        }
        return result;
    } catch (SQLException e) {
        throw new DatabaseException(e);
    }
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) RecordContext(org.parosproxy.paros.db.RecordContext) ResultSet(java.sql.ResultSet) DatabaseException(org.parosproxy.paros.db.DatabaseException)

Aggregations

DatabaseException (org.parosproxy.paros.db.DatabaseException)153 SQLException (java.sql.SQLException)113 ResultSet (java.sql.ResultSet)61 ArrayList (java.util.ArrayList)28 HttpMalformedHeaderException (org.parosproxy.paros.network.HttpMalformedHeaderException)19 PreparedStatement (java.sql.PreparedStatement)11 Session (org.parosproxy.paros.model.Session)11 HttpMessage (org.parosproxy.paros.network.HttpMessage)11 RecordHistory (org.parosproxy.paros.db.RecordHistory)9 RecordAlert (org.parosproxy.paros.db.RecordAlert)7 RecordContext (org.parosproxy.paros.db.RecordContext)7 Vector (java.util.Vector)6 URIException (org.apache.commons.httpclient.URIException)6 IOException (java.io.IOException)5 TableHistory (org.parosproxy.paros.db.TableHistory)5 HistoryReference (org.parosproxy.paros.model.HistoryReference)5 StructuralSiteNode (org.zaproxy.zap.model.StructuralSiteNode)5 Matcher (java.util.regex.Matcher)4 PatternSyntaxException (java.util.regex.PatternSyntaxException)4 JSONException (net.sf.json.JSONException)4