zaproxy/zaproxy · error · DatabaseException
SQLException wrapped in DatabaseException
Error message
SQLException wrapped in DatabaseException
What it means
SqlTableParam.insert executes 'param.ps.insert', retrieves the generated key via psInsert.getLastInsertedId(), and then calls read(id) to return the new RecordParam. Any SQLException in the INSERT, the key retrieval, or the follow-up read is wrapped in DatabaseException. Because insert also calls read, failures from the read path (error 242) can be reported here too.
Source
Thrown at zap/src/main/java/org/zaproxy/zap/db/sql/SqlTableParam.java:130
SqlPreparedStatementWrapper psInsert = null;
try {
psInsert = DbSQL.getSingleton().getPreparedStatement("param.ps.insert");
psInsert.getPs().setString(1, site);
psInsert.getPs().setString(2, type);
psInsert.getPs().setString(3, name);
psInsert.getPs().setInt(4, used);
psInsert.getPs().setString(5, flags);
psInsert.getPs().setString(6, values);
psInsert.getPs().executeUpdate();
long id;
try (ResultSet rs = psInsert.getLastInsertedId()) {
rs.next();
id = rs.getLong(1);
}
return read(id);
} catch (SQLException e) {
throw new DatabaseException(e);
} finally {
DbSQL.getSingleton().releasePreparedStatement(psInsert);
}
}
@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);View on GitHub (pinned to 9d1970a436)
Solutions
- Check e.getCause() for constraint violation vs connection failure
- Ensure no bound value is null or exceeds the column's declared size
- Confirm getLastInsertedId() support for the configured DB (HSQLDB identity columns)
- Retry the operation if the DB was temporarily locked; otherwise check session health
Example fix
// before psInsert.getPs().setString(3, values); // values may be null // after psInsert.getPs().setString(3, values != null ? values : ""); // guard nulls before insert
Defensive patterns
Strategy: try-catch
Validate before calling
// Sanitize inputs before insert String safeName = name == null ? "" : name; String safeValues = values == null ? "" : (values.length() > MAX ? values.substring(0, MAX) : values);
Type guard
static SQLException asSqlCause(DatabaseException e) {
return (e.getCause() instanceof SQLException) ? (SQLException) e.getCause() : null;
} Try / catch
try {
RecordParam rp = tableParam.insert(scanId, name, type, used, flags, values);
} catch (DatabaseException e) {
SQLException sql = asSqlCause(e);
if (sql != null && sql.getMessage().contains("integrity")) {
logger.warn("Constraint violation inserting param: " + sql.getMessage());
} else {
logger.error("insert failed", e);
}
} Prevention
- Null-guard and length-limit name/flags/values before insert
- Don't insert concurrently from many threads on the same session
- Verify HSQLDB identity-column support for getLastInsertedId()
- Check e.getCause() for constraint vs connection errors
When it happens
Trigger: Calling insert(scanId, name, type, used, flags, values) when the connection is broken, a NOT NULL/constraint is violated (e.g., null name/values), getLastInsertedId() returns an empty ResultSet, or the subsequent read(id) throws.
Common situations: Inserting params with null/oversized values exceeding column size; concurrent inserts with DB lock contention on HSQLDB; session DB closed during active scan.
Related errors
- new DatabaseException(e)
- SQLException wrapped in DatabaseException
- SQLException wrapped in DatabaseException
- SQLException wrapped in DatabaseException
- Recovering {} times.
AI-assisted analysis of zaproxy/zaproxy@9d1970a436 (2026-09-05).
Data as JSON: /api/errors/bf92440ec3da26d2.
Report an issue: GitHub.