4.2 Programmatic API
The Programmatic API is based on JdbcTemplate and accesses the database with SQL strings as the primary interface. It is the lowest-level, most flexible relational database entry point in dbVisitor.
Best For
- You already have clear SQL and want lightweight execution.
- SQL is complex — e.g. JOINs, subqueries, window functions, database-specific syntax.
- You need direct control over batch execution, stored procedures, callbacks, or connection-level operations.
- You do not want to set up object mapping for the current operation.
Not Best For
- Lots of single-table CRUD with repetitive SQL — consider Mapper API (BaseMapper) first.
- You want DAO organized as interfaces — consider Mapper API first.
- You want to generate SQL with chainable conditions — consider Builder API first.
Minimal Example
With DataSource
DataSource dataSource = ...;
JdbcTemplate jdbc = new JdbcTemplate(dataSource);
List<User> users = jdbc.queryForList(
"select * from users where age >= :age",
CollectionUtils.asMap("age", 18),
User.class);
With Connection
Connection conn = ...;
JdbcTemplate jdbc = new JdbcTemplate(conn);
List<User> users = jdbc.queryForList(
"select * from users where age >= :age",
CollectionUtils.asMap("age", 18),
User.class);
Learn More
- JdbcTemplate: full capability entry point.
- Parameter Passing: positional parameters, named parameters, interface-based parameter passing.
- Result Handling: RowMapper, Map, ResultSetExtractor and other result processing approaches.