Executes a SQL query as a prepared statement, setting its fields to the elements of the vararg passed, returning the value in the first column of the first row in the results @param query The SQL query to execute @param fields A vararg of the fields to set in the prepared statement @param T
(String query, Object... fields)
| 235 | * @return The value in the first column of the first row of the returned results, or null if none is present |
| 236 | */ |
| 237 | public <T> T querySingleResult(String query, Object... fields) { |
| 238 | try { |
| 239 | PreparedStatement statement = prepareStatement(query, fields); |
| 240 | ResultSet results = statement.executeQuery(); |
| 241 | if (!results.next()) { |
| 242 | return null; |
| 243 | } |
| 244 | T obj = (T) results.getObject(1); |
| 245 | results.close(); |
| 246 | statement.close(); |
| 247 | return obj; |
| 248 | } catch (SQLException e) { |
| 249 | sneakyThrow(e); |
| 250 | return null; |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | /** |
| 255 | * Executes a SQL query as a prepared statement, setting its fields to the elements of the vararg passed, |
no test coverage detected