Skip to content

❓ JDBC update

❗️UpdateSpec
  • @JdbcUpdate define a method which will execute SQL updates
    • create prepareStatement
    • fill parameter from the method
    • configure statement
    • execute and process the Statement.executeUpdate
    • process possible generated values and return them
  • ✅ the value of @JdbcUpdate must contain a valid SQL select statement with named parameters (:name) as described in param binding
  • ✅ For record parameters the SQL may expand component names and values:
    • :customer.{names} expands to the record component names
    • :customer.{values} expands to the record component values
    • :customer.* is an alias for :customer.{values}
    • if the record parameter uses @JdbcConverterName("..."), those expansions are invalid and only :customer is allowed
  • ✅ Return types may be void, int, or boolean;
    • int will return the result of executeUpdate
    • boolean returns true when at least one row is affected.
  • ✅ Returning generated values requires @JdbcUpdate(returnGeneratedValues = ...). The method must return a non-null, non-collection type that can be mapped via @JdbcToJava.
    • GENERATED_KEYS: The processor calls getGeneratedKeys()
    • EXECUTE_QUERY: The processor calls executeQuery()
    • DEFAULT: The processor uses the default value from the configuration
    • return type must be non-null or unspecific
❗️BatchUpdateSpec
  • @JdbcBatchUpdate define a method which will execute SQL updates in batch ‘mode’
  • For batch operations, declare the return type as an inner interface extending JdbcBatch.
  • the Result must be non-null or unspecific
  • supported annotations
    • @JdbcBatchSize on the method or on an parameter for dynamic
  • ✅ Define the @JdbcUpdate method in the interface The processor emits a nested implementation that collects parameters, honours @JdbcBatchSize (constant or parameter), and delegates to PreparedStatement#addBatch().