JdbcTemplate: add queryOne method
This commit is contained in:
@@ -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}''",
|
||||
|
||||
Reference in New Issue
Block a user