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

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

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

Query.buildPreparedStatement介绍

暂无

代码示例

代码示例来源:origin: aaberg/sql2o

PreparedStatement buildPreparedStatement() {
  return buildPreparedStatement(true);
}

代码示例来源:origin: aaberg/sql2o

public ResultSetIterableBase() {
  try {
    start = System.currentTimeMillis();
    logExecution();
    rs = buildPreparedStatement().executeQuery();
    afterExecQuery = System.currentTimeMillis();
  }
  catch (SQLException ex) {
    throw new Sql2oException("Database error: " + ex.getMessage(), ex);
  }
}

代码示例来源:origin: aaberg/sql2o

/**
 * Adds a set of parameters to this <code>Query</code>
 * object's batch of commands. <br/>
 *
 * If maxBatchRecords is more than 0, executeBatch is called upon adding that many
 * commands to the batch. <br/>
 *
 * The current number of batched commands is accessible via the <code>getCurrentBatchRecords()</code>
 * method.
 */
public Query addToBatch(){
  try {
    buildPreparedStatement(false).addBatch();
    if (this.maxBatchRecords > 0){
      if(++this.currentBatchRecords % this.maxBatchRecords == 0) {
        this.executeBatch();
      }
    }
  } catch (SQLException e) {
    throw new Sql2oException("Error while adding statement to batch", e);
  }
  return this;
}

代码示例来源:origin: aaberg/sql2o

public Object executeScalar() {
  long start = System.currentTimeMillis();
  logExecution();
  try (final PreparedStatement ps = buildPreparedStatement();
     final ResultSet rs = ps.executeQuery()) {
    if (rs.next()) {
      Object o = getQuirks().getRSVal(rs, 1);
      long end = System.currentTimeMillis();
      logger.debug("total: {} ms; executed scalar [{}]", new Object[]{
        end - start,
        this.getName() == null ? "No name" : this.getName()
      });
      return o;
    } else {
      return null;
    }
  } catch (SQLException e) {
    this.connection.onException();
    throw new Sql2oException("Database error occurred while running executeScalar: " + e.getMessage(), e);
  } finally {
    closeConnectionIfNecessary();
  }
}

代码示例来源:origin: aaberg/sql2o

public Connection executeUpdate(){
  long start = System.currentTimeMillis();
  try{
    logExecution();
    PreparedStatement statement = buildPreparedStatement();
    this.connection.setResult(statement.executeUpdate());
    this.connection.setKeys(this.returnGeneratedKeys ? statement.getGeneratedKeys() : null);
    connection.setCanGetKeys(this.returnGeneratedKeys);
  }
  catch(SQLException ex){
    this.connection.onException();
    throw new Sql2oException("Error in executeUpdate, " + ex.getMessage(), ex);
  }
  finally {
    closeConnectionIfNecessary();
  }
  long end = System.currentTimeMillis();
  logger.debug("total: {} ms; executed update [{}]", new Object[]{
      end - start,
      this.getName() == null ? "No name" : this.getName()
  });
  return this.connection;
}

代码示例来源:origin: aaberg/sql2o

public Connection executeBatch() throws Sql2oException {
  long start = System.currentTimeMillis();
  try {
    logExecution();
    PreparedStatement statement = buildPreparedStatement();
    connection.setBatchResult(statement.executeBatch());
    this.currentBatchRecords = 0;
    try {
      connection.setKeys(this.returnGeneratedKeys ? statement.getGeneratedKeys() : null);
      connection.setCanGetKeys(this.returnGeneratedKeys);
    } catch (SQLException sqlex) {
      throw new Sql2oException("Error while trying to fetch generated keys from database. If you are not expecting any generated keys, fix this error by setting the fetchGeneratedKeys parameter in the createQuery() method to 'false'", sqlex);
    }
  }
  catch (Throwable e) {
    this.connection.onException();
    throw new Sql2oException("Error while executing batch operation: " + e.getMessage(), e);
  }
  finally {
    closeConnectionIfNecessary();
  }
  long end = System.currentTimeMillis();
  logger.debug("total: {} ms; executed batch [{}]", new Object[]{
      end - start,
      this.getName() == null ? "No name" : this.getName()
  });
  return this.connection;
}

代码示例来源:origin: biezhi/anima

PreparedStatement buildPreparedStatement() {
  return buildPreparedStatement(true);
}

代码示例来源:origin: org.sql2o/sql2o

PreparedStatement buildPreparedStatement() {
  return buildPreparedStatement(true);
}

代码示例来源:origin: org.sql2o/sql2o

public ResultSetIterableBase() {
  try {
    start = System.currentTimeMillis();
    logExecution();
    rs = buildPreparedStatement().executeQuery();
    afterExecQuery = System.currentTimeMillis();
  }
  catch (SQLException ex) {
    throw new Sql2oException("Database error: " + ex.getMessage(), ex);
  }
}

代码示例来源:origin: biezhi/anima

public ResultSetIterableBase() {
  try {
    start = System.currentTimeMillis();
    logExecution();
    rs = buildPreparedStatement().executeQuery();
    afterExecQuery = System.currentTimeMillis();
  } catch (SQLException ex) {
    throw new Sql2oException("Database error: " + ex.getMessage(), ex);
  }
}

代码示例来源:origin: biezhi/anima

/**
 * Adds a set of parameters to this <code>Query</code>
 * object's batch of commands. <br/>
 * <p>
 * If maxBatchRecords is more than 0, executeBatch is called upon adding that many
 * commands to the batch. <br/>
 * <p>
 * The current number of batched commands is accessible via the <code>getCurrentBatchRecords()</code>
 * method.
 */
public Query addToBatch() {
  try {
    buildPreparedStatement(false).addBatch();
    if (this.maxBatchRecords > 0) {
      if (++this.currentBatchRecords % this.maxBatchRecords == 0) {
        this.executeBatch();
      }
    }
  } catch (SQLException e) {
    throw new Sql2oException("Error while adding statement to batch", e);
  }
  return this;
}

代码示例来源:origin: org.sql2o/sql2o

/**
 * Adds a set of parameters to this <code>Query</code>
 * object's batch of commands. <br/>
 *
 * If maxBatchRecords is more than 0, executeBatch is called upon adding that many
 * commands to the batch. <br/>
 *
 * The current number of batched commands is accessible via the <code>getCurrentBatchRecords()</code>
 * method.
 */
public Query addToBatch(){
  try {
    buildPreparedStatement(false).addBatch();
    if (this.maxBatchRecords > 0){
      if(++this.currentBatchRecords % this.maxBatchRecords == 0) {
        this.executeBatch();
      }
    }
  } catch (SQLException e) {
    throw new Sql2oException("Error while adding statement to batch", e);
  }
  return this;
}

代码示例来源:origin: biezhi/anima

public Object executeScalar() {
  long start = System.currentTimeMillis();
  try {
    logExecution();
    ResultSet rs = buildPreparedStatement().executeQuery();
    if (rs.next()) {
      Object o = getQuirks().getRSVal(rs, 1);
      if (Anima.of().isEnableSQLStatistic() && log.isDebugEnabled()) {
        long end = System.currentTimeMillis();
        log.debug("total: {} ms; executed scalar [{}]", end - start, this.getName() == null ? "No name" : this.getName());
      }
      return o;
    } else {
      return null;
    }
  } catch (SQLException e) {
    this.connection.onException();
    throw new Sql2oException("Database error occurred while running executeScalar: " + e.getMessage(), e);
  } finally {
    closeConnectionIfNecessary();
  }
}

代码示例来源:origin: biezhi/anima

public Connection executeUpdate() {
  long start = System.currentTimeMillis();
  try {
    logExecution();
    PreparedStatement statement = buildPreparedStatement();
    this.connection.setResult(statement.executeUpdate());
    this.connection.setKeys(this.returnGeneratedKeys ? statement.getGeneratedKeys() : null);
    connection.setCanGetKeys(this.returnGeneratedKeys);
  } catch (SQLException ex) {
    this.connection.onException();
    throw new Sql2oException("Error in executeUpdate, " + ex.getMessage(), ex);
  } finally {
    closeConnectionIfNecessary();
  }
  if (Anima.of().isEnableSQLStatistic() && log.isDebugEnabled()) {
    long end = System.currentTimeMillis();
    log.debug("total: {} ms; executed update [{}]", end - start, this.getName() == null ? "No name" : this.getName());
  }
  return this.connection;
}

代码示例来源:origin: org.sql2o/sql2o

public Object executeScalar() {
  long start = System.currentTimeMillis();
  logExecution();
  try (final PreparedStatement ps = buildPreparedStatement();
     final ResultSet rs = ps.executeQuery()) {
    if (rs.next()) {
      Object o = getQuirks().getRSVal(rs, 1);
      long end = System.currentTimeMillis();
      logger.debug("total: {} ms; executed scalar [{}]", new Object[]{
        end - start,
        this.getName() == null ? "No name" : this.getName()
      });
      return o;
    } else {
      return null;
    }
  } catch (SQLException e) {
    this.connection.onException();
    throw new Sql2oException("Database error occurred while running executeScalar: " + e.getMessage(), e);
  } finally {
    closeConnectionIfNecessary();
  }
}

代码示例来源:origin: biezhi/anima

public Connection executeBatch() throws Sql2oException {
  long start = System.currentTimeMillis();
  try {
    logExecution();
    PreparedStatement statement = buildPreparedStatement();
    connection.setBatchResult(statement.executeBatch());
    this.currentBatchRecords = 0;
    try {
      connection.setKeys(this.returnGeneratedKeys ? statement.getGeneratedKeys() : null);
      connection.setCanGetKeys(this.returnGeneratedKeys);
    } catch (SQLException sqlex) {
      throw new Sql2oException("Error while trying to fetch generated keys from database. If you are not expecting any generated keys, fix this error by setting the fetchGeneratedKeys parameter in the createQuery() method to 'false'", sqlex);
    }
  } catch (Throwable e) {
    this.connection.onException();
    throw new Sql2oException("Error while executing batch operation: " + e.getMessage(), e);
  } finally {
    closeConnectionIfNecessary();
  }
  if (Anima.of().isEnableSQLStatistic() && log.isDebugEnabled()) {
    long end = System.currentTimeMillis();
    log.debug("total: {} ms; executed batch [{}]", end - start, this.getName() == null ? "No name" : this.getName());
  }
  return this.connection;
}

代码示例来源:origin: org.sql2o/sql2o

public Connection executeUpdate(){
  long start = System.currentTimeMillis();
  try{
    logExecution();
    PreparedStatement statement = buildPreparedStatement();
    this.connection.setResult(statement.executeUpdate());
    this.connection.setKeys(this.returnGeneratedKeys ? statement.getGeneratedKeys() : null);
    connection.setCanGetKeys(this.returnGeneratedKeys);
  }
  catch(SQLException ex){
    this.connection.onException();
    throw new Sql2oException("Error in executeUpdate, " + ex.getMessage(), ex);
  }
  finally {
    closeConnectionIfNecessary();
  }
  long end = System.currentTimeMillis();
  logger.debug("total: {} ms; executed update [{}]", new Object[]{
      end - start,
      this.getName() == null ? "No name" : this.getName()
  });
  return this.connection;
}

代码示例来源:origin: org.sql2o/sql2o

public Connection executeBatch() throws Sql2oException {
  long start = System.currentTimeMillis();
  try {
    logExecution();
    PreparedStatement statement = buildPreparedStatement();
    connection.setBatchResult(statement.executeBatch());
    this.currentBatchRecords = 0;
    try {
      connection.setKeys(this.returnGeneratedKeys ? statement.getGeneratedKeys() : null);
      connection.setCanGetKeys(this.returnGeneratedKeys);
    } catch (SQLException sqlex) {
      throw new Sql2oException("Error while trying to fetch generated keys from database. If you are not expecting any generated keys, fix this error by setting the fetchGeneratedKeys parameter in the createQuery() method to 'false'", sqlex);
    }
  }
  catch (Throwable e) {
    this.connection.onException();
    throw new Sql2oException("Error while executing batch operation: " + e.getMessage(), e);
  }
  finally {
    closeConnectionIfNecessary();
  }
  long end = System.currentTimeMillis();
  logger.debug("total: {} ms; executed batch [{}]", new Object[]{
      end - start,
      this.getName() == null ? "No name" : this.getName()
  });
  return this.connection;
}

相关文章