Class SqlParamBuilder

java.lang.Object
org.ujorm.tools.sql.SqlParamBuilder
All Implemented Interfaces:
AutoCloseable

public class SqlParamBuilder extends Object implements AutoCloseable
Very light class to simplify work with JDBC. Original source: GitHub Licence: Apache License, Version 2.0

Sample of usage

 try (var builder = new SqlParamBuilder(dbConnection)) {
      List<Employee> employees = builder.sql("""
                SELECT t.id, t.name, t.created
                FROM employee t
                WHERE t.id > :id
                  AND t.code IN (:code)
                ORDER BY t.id
                """)
        .bind("id", 10)
        .bind("code", "T", "V")
        .streamMap(rs -> new Employee(
                rs.getInt("id"),
                rs.getString("name"),
                rs.getObject("created", LocalDate.class)))
        .toList();
 }
 
Since:
2.26
Author:
Pavel Ponec, https://github.com/pponec
  • Field Details

    • sqlTemplate

      @Nullable protected @Nullable String sqlTemplate
  • Constructor Details

    • SqlParamBuilder

      public SqlParamBuilder(@NotNull @NotNull Connection dbConnection)
  • Method Details