Search in sources :

Example 11 with DatabaseException

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

the class SqlTableParam method update.

/* (non-Javadoc)
	 * @see org.parosproxy.paros.db.paros.TableParam#update(long, int, java.lang.String, java.lang.String)
	 */
@Override
public synchronized void update(long paramId, int used, String flags, String values) throws DatabaseException {
    SqlPreparedStatementWrapper psUpdate = null;
    try {
        psUpdate = DbSQL.getSingleton().getPreparedStatement("param.ps.update");
        psUpdate.getPs().setInt(1, used);
        psUpdate.getPs().setString(2, flags);
        psUpdate.getPs().setString(3, values);
        psUpdate.getPs().setLong(4, paramId);
        psUpdate.getPs().executeUpdate();
    } catch (SQLException e) {
        throw new DatabaseException(e);
    } finally {
        DbSQL.getSingleton().releasePreparedStatement(psUpdate);
    }
}
Also used : SQLException(java.sql.SQLException) DatabaseException(org.parosproxy.paros.db.DatabaseException)

Example 12 with DatabaseException

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

the class SqlTableScan method read.

/* (non-Javadoc)
	 * @see org.parosproxy.paros.db.paros.TableScan#read(int)
	 */
@Override
public synchronized RecordScan read(int scanId) throws DatabaseException {
    SqlPreparedStatementWrapper psRead = null;
    try {
        psRead = DbSQL.getSingleton().getPreparedStatement("scan.ps.read");
        psRead.getPs().setInt(1, scanId);
        try (ResultSet rs = psRead.getPs().executeQuery()) {
            RecordScan result = build(rs);
            return result;
        }
    } catch (SQLException e) {
        throw new DatabaseException(e);
    } finally {
        DbSQL.getSingleton().releasePreparedStatement(psRead);
    }
}
Also used : RecordScan(org.parosproxy.paros.db.RecordScan) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) DatabaseException(org.parosproxy.paros.db.DatabaseException)

Example 13 with DatabaseException

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

the class SqlTableAlert method updateTable.

// ZAP: Added the method.
private void updateTable(Connection connection) throws DatabaseException {
    try {
        // Add the SOURCEHISTORYID column to the db if necessary
        if (!DbUtils.hasColumn(connection, TABLE_NAME, SOURCEHISTORYID)) {
            DbUtils.executeAndClose(connection.prepareStatement(DbSQL.getSQL("alert.ps.addsourcehistoryid")));
        }
        // Add the ATTACK column to the db if necessary
        if (!DbUtils.hasColumn(connection, TABLE_NAME, ATTACK)) {
            DbUtils.executeAndClose(connection.prepareStatement(DbSQL.getSQL("alert.ps.addattack")));
        }
        if (!DbUtils.hasColumn(connection, TABLE_NAME, EVIDENCE)) {
            // Evidence, cweId and wascId all added at the same time
            DbUtils.executeAndClose(connection.prepareStatement(DbSQL.getSQL("alert.ps.addevidence")));
            DbUtils.executeAndClose(connection.prepareStatement(DbSQL.getSQL("alert.ps.addcweid")));
            DbUtils.executeAndClose(connection.prepareStatement(DbSQL.getSQL("alert.ps.addwascid")));
        }
        if (!DbUtils.hasIndex(connection, TABLE_NAME, ALERT_INDEX)) {
            // this speads up session loading
            DbUtils.executeAndClose(connection.prepareStatement(DbSQL.getSQL("alert.ps.addalertindex")));
        }
        if (!DbUtils.hasColumn(connection, TABLE_NAME, SOURCEID)) {
            DbUtils.executeAndClose(connection.prepareStatement(DbSQL.getSQL("alert.ps.addsourceid")));
            DbUtils.executeAndClose(connection.prepareStatement(DbSQL.getSQL("alert.ps.addsourceidindex")));
        }
    } catch (SQLException e) {
        throw new DatabaseException(e);
    }
}
Also used : SQLException(java.sql.SQLException) DatabaseException(org.parosproxy.paros.db.DatabaseException)

Example 14 with DatabaseException

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

the class SqlTableContext method deleteAllDataForContextAndType.

/* (non-Javadoc)
	 * @see org.parosproxy.paros.db.paros.TableContext#deleteAllDataForContextAndType(int, int)
	 */
@Override
public synchronized void deleteAllDataForContextAndType(int contextId, int type) throws DatabaseException {
    SqlPreparedStatementWrapper psDeleteAllDataForContextAndType = null;
    try {
        psDeleteAllDataForContextAndType = DbSQL.getSingleton().getPreparedStatement("context.ps.alldataforcontexttype");
        psDeleteAllDataForContextAndType.getPs().setInt(1, contextId);
        psDeleteAllDataForContextAndType.getPs().setInt(2, type);
        psDeleteAllDataForContextAndType.getPs().executeUpdate();
    } catch (SQLException e) {
        throw new DatabaseException(e);
    } finally {
        DbSQL.getSingleton().releasePreparedStatement(psDeleteAllDataForContextAndType);
    }
}
Also used : SQLException(java.sql.SQLException) DatabaseException(org.parosproxy.paros.db.DatabaseException)

Example 15 with DatabaseException

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

the class SqlTableContext method deleteAllDataForContext.

/* (non-Javadoc)
	 * @see org.parosproxy.paros.db.paros.TableContext#deleteAllDataForContext(int)
	 */
@Override
public synchronized void deleteAllDataForContext(int contextId) throws DatabaseException {
    SqlPreparedStatementWrapper psDeleteAllDataForContext = null;
    try {
        psDeleteAllDataForContext = DbSQL.getSingleton().getPreparedStatement("context.ps.alldataforcontext");
        psDeleteAllDataForContext.getPs().setInt(1, contextId);
        psDeleteAllDataForContext.getPs().executeUpdate();
    } catch (SQLException e) {
        throw new DatabaseException(e);
    } finally {
        DbSQL.getSingleton().releasePreparedStatement(psDeleteAllDataForContext);
    }
}
Also used : SQLException(java.sql.SQLException) 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