-
Notifications
You must be signed in to change notification settings - Fork 38.4k
Add "queryForFirst" methods to JdbcTemplate for querying first row of ResultSet #34666
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
At this point, I prefer to leave Since |
See spring-projects#34666 (comment) Signed-off-by: Yanming Zhou <[email protected]>
I created GH-34709 to address this part, please review. |
See spring-projects#34666 (comment) Signed-off-by: Yanming Zhou <[email protected]>
Do you mean add a method like this?
It's a bit weird only IMHO, people used to reuse shared instance like auto-configured one by Spring Boot, instead of creating new |
FYI, I created prototype to introduce new methods for |
I'm tend to keep |
It's very common to get first row of ResultSet or
null
for empty ResultSet, for exampleJdbcStepExecutionDao::getLastStepExecution
from Spring Batch, see spring-projects/spring-batch#4798 for background.We should call
Statement::setMaxRows
as hints (some legacy driver may not honer it) before executing, and only consume first row of the ResultSet.Not sure about the return type,
@Nullable T
orOptional<T>
is better?If this proposal is accepted, then
Optional<T> first()
should be added toJdbcClient
.Why not
queryForList
?It will load all rows into memory.
Why not
queryForObject
?It requires exactly one row, but the ResultSet may be empty, and there is no standard syntax to limit one row across all databases.
Why not
queryForStream().findFirst()
?The result stream need be closed explicitly, and
maxRows
is set for wholeJdbcTemplate
, we need specific 1 only for this query.The text was updated successfully, but these errors were encountered: