MCPcopy Create free account
hub / github.com/boxbeam/RedLib / querySingleResult

Method querySingleResult

src/redempt/redlib/sql/SQLHelper.java:237–252  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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,

Callers 1

selectMethod · 0.80

Calls 5

prepareStatementMethod · 0.95
sneakyThrowMethod · 0.95
closeMethod · 0.65
nextMethod · 0.45
getObjectMethod · 0.45

Tested by

no test coverage detected