0

JdbcTemplate: add queryOne method

This commit is contained in:
2021-01-03 16:07:40 +03:00
parent c963c4bd60
commit f821691308
3 changed files with 26 additions and 0 deletions

View File

@@ -17,6 +17,7 @@ import java.sql.SQLException;
import java.text.MessageFormat;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.StringJoiner;
import java.util.logging.Logger;
import java.util.stream.Collectors;
@@ -99,6 +100,17 @@ class JdbcTemplateTest {
assertEquals(DATA[0][1], value);
}
@Test
void testQuery_Simple_Optional() {
String sql = MessageFormat.format("SELECT {2} FROM {0} WHERE {1} LIKE ''{3}''",
TABLE_NAME, COLUMN_NAME, COLUMN_VALUE, DATA[0][0]);
Optional<Integer> optValue = jdbcTemplate.queryOne(sql, rs -> rs.getInt(1));
assertTrue(optValue.isPresent());
assertEquals(DATA[0][1], optValue.get());
}
@Test
void testQuery_Simple_List() {
String sql = MessageFormat.format("SELECT {2} FROM {0} WHERE {1} LIKE ''{3}'' OR {1} LIKE ''{4}''",