✅ JDBC native
Sometimes a developer needs to work with the Connection directly, create statements,
execute them, and process the results in a way that the annotations do not cover.
The annotation processor therefore provides a mechanism to call a hand-written method.
- Bridges to a user-provided static method; by default the processor searches
within the same interface, while
clsandmethodoverride the target. - The target method must be static and accept a
java.sql.Connectionas its first parameter, followed by the interface parameters in the same order and type.- The first parameter must be
java.sql.Connection. - The remaining parameters must match the interface method in count and type.
- The return type must be assignable to the interface method’s return type.
- Nullness semantics must stay compatible between source and target signatures.
- The first parameter must be
- Exception handling:
- Any
SQLExceptionis wrapped inJdbcException. - All other exceptions must either be runtime exceptions or be type-compatible with the interface method signature.
- Any
Example
Section titled “Example”@JdbcNativeList<String> getTables(String tableNamePattern);
static List<String> getTables(Connection con, String tableNamePattern) throws SQLException { DatabaseMetaData md = con.getMetaData(); try (var rs0 = md.getTables(null, "PUBLIC", tableNamePattern, new String[]{"TABLE"})) { return ResultSetUtils.toList(rs0, (rs) -> { return rs.getString("TABLE_TYPE") + ", " + rs.getString("TABLE_CAT") + ", " + rs.getString("TABLE_SCHEM") + ", " + rs.getString("TABLE_NAME"); }); }}