本文整理了Java中org.sql2o.Query.executeScalar
方法的一些代码示例,展示了Query.executeScalar
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.executeScalar
方法的具体详情如下:
包路径:org.sql2o.Query
类名称:Query
方法名:executeScalar
暂无
代码示例来源:origin: aaberg/sql2o
public <V> V executeScalar(Converter<V> converter){
try {
//noinspection unchecked
return converter.convert(executeScalar());
} catch (ConverterException e) {
throw new Sql2oException("Error occured while converting value from database", e);
}
}
代码示例来源:origin: aaberg/sql2o
public <V> V executeScalar(Class<V> returnType){
try {
Converter<V> converter;
//noinspection unchecked
converter = throwIfNull(returnType, getQuirks().converterOf(returnType));
//noinspection unchecked
logExecution();
return executeScalar(converter);
} catch (ConverterException e) {
throw new Sql2oException("Error occured while converting value from database to type " + returnType, e);
}
}
代码示例来源:origin: iNPUTmice/caas
/**
* Gets iteration number for next iteration, 0 if no iteration exists
*
* @param connection
* @return
*/
private static int getNextIterationNumber(Connection connection) {
String query = "select max(iteration_number) from periodic_test_iterations";
try {
return connection.createQuery(query).executeScalar(Integer.class) + 1;
} catch (Exception ex) {
return 0;
}
}
代码示例来源:origin: org.sql2o/sql2o
public <V> V executeScalar(Converter<V> converter){
try {
//noinspection unchecked
return converter.convert(executeScalar());
} catch (ConverterException e) {
throw new Sql2oException("Error occured while converting value from database", e);
}
}
代码示例来源:origin: biezhi/anima
public <V> V executeScalar(Converter<V> converter) {
try {
//noinspection unchecked
return converter.convert(executeScalar());
} catch (ConverterException e) {
throw new Sql2oException("Error occured while converting value from database", e);
}
}
代码示例来源:origin: iNPUTmice/caas
public static Instant getLastRunFor(Connection connection, String domain) {
Instant lastRun = connection.createQuery("select max(timestamp) from current_tests where domain=:domain")
.addParameter("domain", domain)
.executeScalar(Instant.class);
return lastRun;
}
代码示例来源:origin: iNPUTmice/caas
public static boolean isSubscribed(Connection connection, String email, String domain) {
boolean subscribed = connection.createQuery(
"select count(email) from subscribers " +
"where domain = :domain and email = :email")
.addParameter("email", email)
.addParameter("domain", domain)
.executeScalar(Integer.class) > 0;
return subscribed;
}
代码示例来源:origin: junicorn/mario
@SuppressWarnings("unchecked")
public static Map<String, Object> getMap(String sql, Map<String, Object> params){
Connection con = sql2o.open();
Query query = con.createQuery(sql);
executeQuery(query, params);
Map<String, Object> t = (Map<String, Object>) query.executeScalar();
con.close();
return t;
}
代码示例来源:origin: biezhi/anima
public <V> V executeScalar(Class<V> returnType) {
try {
Converter<V> converter;
//noinspection unchecked
converter = throwIfNull(returnType, getQuirks().converterOf(returnType));
//noinspection unchecked
logExecution();
return executeScalar(converter);
} catch (ConverterException e) {
throw new Sql2oException("Error occured while converting value from database to type " + returnType, e);
}
}
代码示例来源:origin: org.sql2o/sql2o
public <V> V executeScalar(Class<V> returnType){
try {
Converter<V> converter;
//noinspection unchecked
converter = throwIfNull(returnType, getQuirks().converterOf(returnType));
//noinspection unchecked
logExecution();
return executeScalar(converter);
} catch (ConverterException e) {
throw new Sql2oException("Error occured while converting value from database to type " + returnType, e);
}
}
代码示例来源:origin: biezhi/anima
/**
* Querying a model
*
* @param type model type
* @param sql sql statement
* @param params params
* @param <S>
* @return S
*/
public <S> S queryOne(Class<S> type, String sql, Object[] params) {
Connection conn = getConn();
try {
Query query = conn.createQuery(sql)
.withParams(params)
.setAutoDeriveColumnNames(true)
.throwOnMappingFailure(false);
return ifReturn(AnimaUtils.isBasicType(type),
() -> query.executeScalar(type),
() -> query.executeAndFetchFirst(type));
} finally {
this.closeConn(conn);
this.clean(null);
}
}
内容来源于网络,如有侵权,请联系作者删除!