Skip to content

JDBC Native

@JdbcNative defines a JDBC method that delegates to a handwritten static method. The generated method obtains the active Connection and passes it to the native target method.

Native method nullness compatibility follows the Nullness Contract.

❗️General ❗️Not found

Without annotation attributes, the target method is searched in the same interface and uses the same method name as the @JdbcNative method.

@JdbcNative(cls = ...) changes the target class. @JdbcNative(method = "...") changes the target method name.

Only static methods with the target name are candidates. If no static candidate exists, the target method is not found. If static candidates exist but none of them is callable, the @JdbcNative method is invalid and the callable mismatch is reported.

Overloaded target methods are allowed when exactly one static overload is callable for the @JdbcNative method.

❗️Parameters ❗️Return type

The target method must accept java.sql.Connection as its first parameter. All remaining target parameters must match the @JdbcNative method parameters in count, order, type, and nullness.

The target return type must be compatible with the @JdbcNative method return type. Return nullness must also be compatible.

void native methods are supported when both methods return void.

❗️Exceptions

SQLException thrown by the target method is wrapped in JdbcException. Runtime exceptions are propagated unchanged.

Other checked exceptions must be compatible with the @JdbcNative method signature. If the target method declares an incompatible checked exception, the @JdbcNative method is invalid.

The target method receives the active JDBC Connection. It must not close that connection. JDBC resources created by the target method, such as statements and result sets, are owned by the target method.