Search in sources :

Example 96 with DatabaseException

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

the class ParosTableParam method reconnect.

@Override
protected void reconnect(Connection conn) throws DatabaseException {
    try {
        if (!DbUtils.hasTable(conn, TABLE_NAME)) {
            // Need to create the table
            DbUtils.executeAndClose(conn.prepareStatement("CREATE cached TABLE PARAM (paramid bigint generated by default as identity (start with 1), site varchar(32768) not null, " + "type varchar(32768) not null, name varchar(32768) not null, used int not null, flags varchar(32768) not null, vals varchar(8388608) not null)"));
        }
        psRead = conn.prepareStatement("SELECT * FROM PARAM WHERE " + PARAMID + " = ?");
        psInsert = conn.prepareStatement("INSERT INTO PARAM (" + SITE + "," + TYPE + "," + NAME + "," + USED + "," + FLAGS + "," + VALUES + ") VALUES (?, ?, ?, ?, ?, ?)");
        psGetIdLastInsert = conn.prepareCall("CALL IDENTITY();");
        psUpdate = conn.prepareStatement("UPDATE PARAM SET " + USED + " = ?," + FLAGS + " = ?," + VALUES + " = ? " + "WHERE " + PARAMID + " = ?");
        psGetAll = conn.prepareStatement("SELECT * FROM PARAM");
    } catch (SQLException e) {
        throw new DatabaseException(e);
    }
}
Also used : SQLException(java.sql.SQLException) DatabaseException(org.parosproxy.paros.db.DatabaseException)

Example 97 with DatabaseException

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

the class ParosTableParam 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 {
    try {
        psUpdate.setInt(1, used);
        psUpdate.setString(2, flags);
        psUpdate.setString(3, values);
        psUpdate.setLong(4, paramId);
        psUpdate.executeUpdate();
    } catch (SQLException e) {
        throw new DatabaseException(e);
    }
}
Also used : SQLException(java.sql.SQLException) DatabaseException(org.parosproxy.paros.db.DatabaseException)

Example 98 with DatabaseException

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

the class ParosTableParam method insert.

/* (non-Javadoc)
	 * @see org.parosproxy.paros.db.paros.TableParam#insert(java.lang.String, java.lang.String, java.lang.String, int, java.lang.String, java.lang.String)
	 */
@Override
public synchronized RecordParam insert(String site, String type, String name, int used, String flags, String values) throws DatabaseException {
    try {
        psInsert.setString(1, site);
        psInsert.setString(2, type);
        psInsert.setString(3, name);
        psInsert.setInt(4, used);
        psInsert.setString(5, flags);
        psInsert.setString(6, values);
        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 99 with DatabaseException

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

the class ExtensionLoader method startLifeCycle.

/**
     * Initialize a specific Extension
     * @param ext the Extension that need to be initialized
     * @throws DatabaseUnsupportedException 
     * @throws DatabaseException 
     */
public void startLifeCycle(Extension ext) throws DatabaseException, DatabaseUnsupportedException {
    ext.init();
    ext.databaseOpen(model.getDb());
    ext.initModel(model);
    ext.initXML(model.getSession(), model.getOptionsParam());
    ext.initView(view);
    ExtensionHook extHook = new ExtensionHook(model, view);
    try {
        ext.hook(extHook);
        extensionHooks.put(ext, extHook);
        hookContextDataFactories(ext, extHook);
        hookApiImplementors(ext, extHook);
        if (view != null) {
            // no need to hook view if no GUI
            hookView(ext, view, extHook);
            hookMenu(view, extHook);
        }
        hookOptions(extHook);
        ext.optionsLoaded();
        ext.postInit();
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }
    ext.start();
    Proxy proxy = Control.getSingleton().getProxy();
    hookProxyListeners(proxy, extHook.getProxyListenerList());
    hookPersistentConnectionListeners(proxy, extHook.getPersistentConnectionListener());
    hookConnectRequestProxyListeners(proxy, extHook.getConnectRequestProxyListeners());
    if (view != null) {
        hookSiteMapListeners(view.getSiteTreePanel(), extHook.getSiteMapListenerList());
    }
}
Also used : Proxy(org.parosproxy.paros.control.Proxy) DatabaseException(org.parosproxy.paros.db.DatabaseException) DatabaseUnsupportedException(org.parosproxy.paros.db.DatabaseUnsupportedException)

Example 100 with DatabaseException

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

the class ParosTableAlert method getAlertListByScan.

public Vector<Integer> getAlertListByScan(int scanId) throws DatabaseException {
    try {
        try (PreparedStatement psReadScan = getConnection().prepareStatement("SELECT ALERTID FROM " + TABLE_NAME + " WHERE " + SCANID + " = ?")) {
            Vector<Integer> v = new Vector<>();
            psReadScan.setInt(1, scanId);
            try (ResultSet rs = psReadScan.executeQuery()) {
                while (rs.next()) {
                    // ZAP: Changed to use the method Integer.valueOf.
                    v.add(Integer.valueOf(rs.getInt(ALERTID)));
                }
            }
            return v;
        }
    } catch (SQLException e) {
        throw new DatabaseException(e);
    }
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) Vector(java.util.Vector) 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