311-frameworks-spring-jdbc

Solid

Use when you need to write or review programmatic JDBC with Spring — including JdbcClient (Spring Framework 7+) as the default API, JdbcTemplate only where batch/streaming APIs require JdbcOperations, NamedParameterJdbcTemplate for legacy named-param code, parameterized SQL, RowMapper mapping to records, batch operations, transactions, safe handling of generated keys, DataAccessException handling, read-only transactions, streaming large result sets, and @JdbcTest slice testing. This should trigger for requests such as Review Java code for Spring JDBC (JdbcTemplate, JdbcClient, NamedParameterJdbcTemplate); Apply best practices for Spring JDBC data access in Java code; Detect and fix SQL injection risks in JDBC code; Improve transaction boundaries or exception handling for JDBC operations. Part of cursor-rules-java project

AI & Automation 393 stars 78 forks Updated today Apache-2.0

Install

View on GitHub

Quality Score: 92/100

Stars 20%
86
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# Spring JDBC — JdbcClient (Spring Framework 7+) Apply Spring JDBC guidelines with JdbcClient as the default; use JdbcTemplate / NamedParameterJdbcTemplate only for legacy code or APIs not covered by JdbcClient (batch updates, KeyHolder, RowCallbackHandler streaming). **What is covered in this Skill?** - Parameterized SQL (never concatenate user input) - JdbcClient fluent API (Spring Framework 7+) — preferred for queries and updates - Named parameters via JdbcClient; NamedParameterJdbcTemplate for legacy migration - RowMapper, query(Class), and records - Batch operations and generated keys (JdbcTemplate / JdbcOperations where needed) - Safe handling of generated keys (KeyHolder; single-row JdbcClient updates) - Service-layer @Transactional boundaries - Read-only transactions (@Transactional(readOnly = true)) - Safe single-row access (optional() / findFirst() vs queryForObject) - Streaming large result sets (RowCallbackHandler, ResultSetExtractor) - DataAccessException handling (DuplicateKeyException, EmptyResultDataAccessException) - @JdbcTest slice testing with @Sql fixtures **Scope:** Apply recommendations based on the reference rules and good/bad code examples. ## Constraints Before applying any Spring JDBC changes, ensure the project compiles. If compilation fails, stop immediately. After applying improvements, run full verification. - **MANDATORY**: Run `./mvnw compile` or `mvn compile` before applying any change - **SAFETY**: If compilation fails, stop immediatel...

Details

Author
jabrena
Repository
jabrena/cursor-rules-java
Created
1 years ago
Last Updated
today
Language
Java
License
Apache-2.0

Integrates with

Similar Skills

Semantically similar based on skill content — not just same category

AI & Automation Solid

312-frameworks-spring-data-jdbc

Use when you need to use Spring Data JDBC with Java records — including entity design with records, repository pattern, immutable updates, aggregate relationships, custom queries, transaction management, and avoiding N+1 problems. This should trigger for requests such as Review Java code for Spring Data JDBC; Apply best practices for Spring Data JDBC in Java code. Part of cursor-rules-java project

393 Updated today
jabrena
AI & Automation Solid

301-frameworks-spring-boot-core

Use when you need to review, improve, or build Spring Boot 4.0.x applications — including proper usage of @SpringBootApplication, component annotations (@Controller, @Service, @Repository), bean definition and scoping, configuration classes and @ConfigurationProperties (with @Validated), component scanning, conditional configuration and profiles, constructor injection, @Primary and @Qualifier for multiple beans of the same type, bean minimization, graceful shutdown, virtual threads, Jakarta EE namespace consistency, and scheduled tasks. This should trigger for requests such as Review Java code for Spring Boot application; Apply best practices for Spring Boot application in Java code. Part of cursor-rules-java project

393 Updated today
jabrena
AI & Automation Solid

511-frameworks-micronaut-jdbc

Use when you need programmatic JDBC in Micronaut — pooled DataSource, parameterized SQL, io.micronaut.transaction.annotation.Transactional, batching, and domain exception translation. Part of the skills-for-java project

393 Updated today
jabrena
AI & Automation Solid

411-frameworks-quarkus-jdbc

Use when you need programmatic JDBC in Quarkus — Agroal DataSource, parameterized SQL, transactions, batching, and Dev Services. Part of the skills-for-java project

393 Updated today
jabrena
AI & Automation Solid

313-frameworks-spring-db-migrations-flyway

Use when you need to add or review Flyway database migrations in a Spring Boot application — Maven dependencies, db/migration scripts, spring.flyway.* configuration, baseline and validation, and alignment with JDBC or Spring Data JDBC. Part of the skills-for-java project

393 Updated today
jabrena