org.sql2o.Query.executeScalar()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(4.1k)|赞(0)|评价(0)|浏览(101)

本文整理了Java中org.sql2o.Query.executeScalar方法的一些代码示例,展示了Query.executeScalar的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.executeScalar方法的具体详情如下:
包路径:org.sql2o.Query
类名称:Query
方法名:executeScalar

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);
  }
}

相关文章