Search in sources :

Example 71 with DatabaseException

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

the class ParosTableTag method getTagsForHistoryID.

/* (non-Javadoc)
	 * @see org.parosproxy.paros.db.paros.TableTag#getTagsForHistoryID(long)
	 */
@Override
public synchronized List<RecordTag> getTagsForHistoryID(long historyId) throws DatabaseException {
    try {
        List<RecordTag> result = new ArrayList<>();
        psGetTagsForHistoryId.setLong(1, historyId);
        try (ResultSet rs = psGetTagsForHistoryId.executeQuery()) {
            while (rs.next()) {
                result.add(new RecordTag(rs.getLong(TAGID), rs.getLong(TAGID), rs.getString(TAG)));
            }
        }
        return result;
    } catch (SQLException e) {
        throw new DatabaseException(e);
    }
}
Also used : RecordTag(org.parosproxy.paros.db.RecordTag) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) DatabaseException(org.parosproxy.paros.db.DatabaseException)

Example 72 with DatabaseException

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

the class ParosTableScan method insert.

/* (non-Javadoc)
	 * @see org.parosproxy.paros.db.paros.TableScan#insert(long, java.lang.String)
	 */
@Override
public synchronized RecordScan insert(long sessionId, String scanName) throws DatabaseException {
    try {
        psInsert.setLong(1, sessionId);
        psInsert.setString(2, scanName);
        psInsert.executeUpdate();
        int id;
        try (ResultSet rs = psGetIdLastInsert.executeQuery()) {
            rs.next();
            id = rs.getInt(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 73 with DatabaseException

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

the class ParosTableScan method build.

private RecordScan build(ResultSet rs) throws DatabaseException {
    try {
        RecordScan scan = null;
        if (rs.next()) {
            scan = new RecordScan(rs.getInt(SCANID), rs.getString(SCANNAME), rs.getDate(SCANTIME));
        }
        rs.close();
        return scan;
    } catch (SQLException e) {
        throw new DatabaseException(e);
    }
}
Also used : RecordScan(org.parosproxy.paros.db.RecordScan) SQLException(java.sql.SQLException) DatabaseException(org.parosproxy.paros.db.DatabaseException)

Example 74 with DatabaseException

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

the class ParosTableSession method insert.

/*
    public synchronized RecordSession read(long sessionId) throws HttpMalformedHeaderException, SQLException {
        psRead.setInt(1, historyId);
        psRead.execute();
        ResultSet rs = psRead.getResultSet();
        return build(rs);
    }
    */
/* (non-Javadoc)
	 * @see org.parosproxy.paros.db.paros.TableSession#insert(long, java.lang.String)
	 */
@Override
public synchronized void insert(long sessionId, String sessionName) throws DatabaseException {
    try {
        psInsert.setLong(1, sessionId);
        psInsert.setString(2, sessionName);
        psInsert.executeUpdate();
    } catch (SQLException e) {
        throw new DatabaseException(e);
    }
}
Also used : SQLException(java.sql.SQLException) DatabaseException(org.parosproxy.paros.db.DatabaseException)

Example 75 with DatabaseException

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

the class ParosTableSession method reconnect.

@Override
protected void reconnect(Connection conn) throws DatabaseException {
    try {
        psReadDate = conn.prepareStatement("SELECT * FROM SESSION WHERE " + LASTACCESS + " < ?");
        psReadAll = conn.prepareStatement("SELECT * FROM SESSION");
        psInsert = conn.prepareStatement("INSERT INTO SESSION (" + SESSIONID + "," + SESSIONNAME + ") VALUES (?, ?)");
        psUpdate = conn.prepareStatement("UPDATE SESSION SET " + SESSIONNAME + " = ?," + LASTACCESS + " = NOW " + "WHERE " + SESSIONID + " = ?");
    } catch (SQLException e) {
        throw new DatabaseException(e);
    }
}
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