org.springframework.jdbc.core.JdbcTemplate.queryForInt()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(8.4k)|赞(0)|评价(0)|浏览(214)

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

JdbcTemplate.queryForInt介绍

暂无

代码示例

代码示例来源:origin: uk.ac.ebi.pride/prideq-core

@Override
public int getPsmCount() {
  JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
  try{
    return jdbcTemplate.queryForInt(
        "SELECT COUNT(*) FROM prideq_psms");
  }catch (DataAccessException e){
    return 0;
  }
}

代码示例来源:origin: Pragmatists/tdd-trainings

@Override
public int itemsOnShelf(int shelfNumber) {
  
  String sql = String.format("select sum(ITEMS) from PRODUCT_SHELF where SHELF_NUMBER='%s'", shelfNumber);
  return template.queryForInt(sql);
}

代码示例来源:origin: uk.ac.ebi.pride/prideq-core

@Override
public int getProteinCount() {
  JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
  try{
    return jdbcTemplate.queryForInt(
        "SELECT COUNT(*) FROM prideq_proteins;");
  }catch (DataAccessException e){
    return 0;
  }
}

代码示例来源:origin: ch.inftec.ju/ju-testing

private void dropTable(String tableName) {
  int res = this.jdbcTemplate.queryForInt("select count(*) from user_tables where table_name=?", tableName);
  if (res > 0) {
    this.jdbcTemplate.update("DROP TABLE " + tableName);
  }
}

代码示例来源:origin: uk.ac.ebi.pride/prideq-core

@Override
public int getUniquePeptideSequenceCount() {
  JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
  try{
    return  jdbcTemplate.queryForInt(
        "SELECT COUNT(DISTINCT(prots_psms_peptide_sequence)) FROM prideq_prots_psms");
  }catch (DataAccessException e){
    return 0;
  }
}

代码示例来源:origin: org.kuali.kfs/kfs-core

/**
 * @see org.kuali.kfs.module.cam.document.dataaccess.DepreciationBatchDao#getFullyDepreciatedAssetCount()
 */
public Integer getFullyDepreciatedAssetCount() {
  int count = getJdbcTemplate().queryForInt("SELECT COUNT(1) FROM CM_CPTLAST_T AST, (SELECT CPTLAST_NBR, (SUM(AST_DEPR1_BASE_AMT - AST_ACUM_DEPR1_AMT) - (SELECT 0.0+CPTLAST_SALVAG_AMT FROM CM_CPTLAST_T X WHERE X.CPTLAST_NBR = Y.CPTLAST_NBR)) BAL FROM CM_AST_PAYMENT_T Y WHERE AST_DEPR1_BASE_AMT IS NOT NULL AND AST_DEPR1_BASE_AMT <> 0.0 AND AST_ACUM_DEPR1_AMT IS NOT NULL AND AST_ACUM_DEPR1_AMT <> 0.0 AND (AST_TRNFR_PMT_CD = 'N' OR AST_TRNFR_PMT_CD = '' OR AST_TRNFR_PMT_CD IS NULL) GROUP BY CPTLAST_NBR) PMT WHERE PMT.BAL = 0.0 AND AST.CPTLAST_NBR = PMT.CPTLAST_NBR");
  return count;
}

代码示例来源:origin: hernad/easyrec

public int getNumberOfActions(Integer tenantId, Integer actionType) {
    StringBuilder query = new StringBuilder("SELECT count(1) as cnt FROM ");
    query.append(BaseActionDAO.DEFAULT_TABLE_NAME);
    query.append(" WHERE ").append(BaseActionDAO.DEFAULT_TENANT_COLUMN_NAME).append("=? ")
        .append(" AND ").append(BaseActionDAO.DEFAULT_ACTION_TYPE_COLUMN_NAME).append("=?");

    final Object[] args = {tenantId, actionType};
    final int[] argTypes = {Types.INTEGER, Types.INTEGER};

    return getJdbcTemplate().queryForInt(query.toString(), args, argTypes);
  }
}

代码示例来源:origin: org.ojbc.bundles.intermediaries/subscription-notification-service-intermediary-common

/**
 * Determine the number of subscriptions owned by the specified owner.
 * @param subscriptionOwner the federation-wide unique identifier for the person that owns the subscriptions
 * @return the count of subscriptions that person owns
 */
public int countSubscriptionsInSearch(@Header("saml_FederationID") String subscriptionOwner) {
  String sqlQuery = "select count(*) from subscription where subscriptionOwner=? and active =1";
  int subscriptionCountForOwner = this.jdbcTemplate.queryForInt(sqlQuery, new Object[] {
    subscriptionOwner
  });
  return subscriptionCountForOwner;
}

代码示例来源:origin: org.fornax.cartridges/fornax-cartridges-sculptor-framework-test

/**
 * counts the number of rows from a table via jdbc
 *
 * @param tableName
 *            name of the table for counting rows
 * @param condition
 *            additional condition
 * @return number of rows
 */
protected int countRowsInTable(String tableName, String condition) {
  return getJdbcTemplate().queryForInt("select count(*) from " + tableName + " " + condition);
}

代码示例来源:origin: hernad/easyrec

private Integer retrieveTenantIdOfRecommendationByIdFromDatabase(Integer recommendationId) {
    StringBuilder query = new StringBuilder("SELECT ");
    query.append(DEFAULT_TENANT_COLUMN_NAME);
    query.append(" FROM ");
    query.append(DEFAULT_TABLE_NAME);
    query.append(" WHERE ");
    query.append(DEFAULT_ID_COLUMN_NAME);
    query.append("=?");

    Object[] args = {recommendationId};
    int[] argTypes = {Types.INTEGER};

    return getJdbcTemplate().queryForInt(query.toString(), args, argTypes);
  }
}

代码示例来源:origin: org.kuali.kfs/kfs-core

/**
 * @see org.kuali.kfs.module.cam.document.dataaccess.DepreciationBatchDao#getTransferDocLockedAssetCount()
 */
public Integer getTransferDocLockedAssetCount() {
  return getJdbcTemplate().queryForInt("select count(1) from CM_AST_TRNFR_DOC_T t inner join FS_DOC_HEADER_T h on t.fdoc_nbr = h.fdoc_nbr where h.fdoc_status_cd ='" + KFSConstants.DocumentStatusCodes.ENROUTE + "'");
}

代码示例来源:origin: org.kuali.kfs/kfs-core

/**
 * @see org.kuali.kfs.module.cam.document.dataaccess.DepreciationBatchDao#getRetireDocLockedAssetCount()
 */
public Integer getRetireDocLockedAssetCount() {
  return getJdbcTemplate().queryForInt("select count(1) from CM_AST_RETIRE_DTL_T t inner join FS_DOC_HEADER_T h on t.fdoc_nbr = h.fdoc_nbr where h.fdoc_status_cd  ='" + KFSConstants.DocumentStatusCodes.ENROUTE + "'");
}

代码示例来源:origin: hernad/easyrec

private int getNewTenantId() {
  StringBuilder query = new StringBuilder("Select MAX(").append(DEFAULT_ID_COLUMN_NAME).append(") FROM ")
      .append(DEFAULT_TABLE_NAME);
  return getJdbcTemplate().queryForInt(query.toString()) + 1;
}

代码示例来源:origin: hernad/easyrec

public Integer getArchiveSize(String tablename) {
  StringBuilder sql = new StringBuilder().append(" SELECT").append("   Count(1) as c ").append(" FROM ")
      .append(tablename);
  try {
    return getJdbcTemplate().queryForInt(sql.toString());
  } catch (Exception e) {
    logger.debug(e);
    return -1;
  }
}

代码示例来源:origin: org.tinygroup/tinydb

public int queryForIntByMap(String sql,Map<String, Object> parameters){
  StringBuffer buf = new StringBuffer();
  ArrayList<Object> paraList = getParamArray(sql, parameters, buf);
  return jdbcTemplate.queryForInt(sql, paraList.toArray());
}

代码示例来源:origin: ch.inftec.ju/ju-dbutil

@Override
  public void execute(Connection conn) {
    JdbcTemplate jt = JuConnUtils.asJdbcTemplate(conn);
    jt.execute(String.format("DROP SCHEMA `%s`", schemaInfo.getName()));
    
    for (String user : users) {
      int cnt = jt.queryForInt(String.format("select count(*) from mysql.user where user = '%s'", user));
      if (cnt > 0) {
        jt.execute(String.format("DROP USER `%s`", user));
      }
    }
  }
});

代码示例来源:origin: stackoverflow.com

DataSource dataSource = getDataSourceFromSomewhere();
DataSourceTransactionManager tm = new DataSourceTransactionManager(dataSource);
JdbcTemplate jdbc = new JdbcTemplate(dataSource);
TransactionStatus tx = tm.getTransaction(new DefaultTransactionDefinition());

int update1 = jdbc.update("insert into employee...");
int employeeId = jdbc.queryForInt(select id from employee...");
int update2 = jdbc.update("insert into employee_department...");

if (employeeId > 0 && update2 > 0) 
  tm.commit(tx);
else
  tm.rollback(tx);

代码示例来源:origin: ch.inftec.ju/ju-testing

/**
 * Tests if the table TEST_A has been created correctly.
 */
@Test
public final void testA() {		
  List<String> columnNames = this.juDbUtils.getColumnNames("TEST_A");
    
  Assert.assertEquals(3, columnNames.size());
  Assert.assertTrue(columnNames.containsAll(JuCollectionUtils.arrayList("AID", "TEXT", "B_FK")));
  
  int cnt = this.jdbcTemplate.queryForInt("select count(*) from test_a");
  Assert.assertEquals(3, cnt);
}

代码示例来源:origin: ebnew/ki4so

protected final boolean authenticateUsernamePasswordInternal(final UsernamePasswordCredential credentials) throws AuthenticationException {
  final String transformedUsername = credentials.getUsername();
  final String encyptedPassword = getPasswordEncoder().encode(credentials.getPassword());
  final int count = getJdbcTemplate().queryForInt(this.sql,
    transformedUsername, encyptedPassword);
  return count > 0;
}

代码示例来源:origin: pl.touk.ormtest/ormtesttest

@Before                            
public void before() throws SQLException {
  SimpleJdbcTestUtils.executeSqlScript(
      new SimpleJdbcTemplate(txContext.getJdbcTemplate()),
      new ClassPathResource("test.sql"),
      true);
  txContext.commitTransactionAndBeginNewOne();
  firstExampleEntity = new ExampleEntity(0, "nameInBefore");
  txContext.getJdbcTemplate().execute("INSERT INTO EXAMPLEENTITIES (name) VALUES ('" + firstExampleEntity.getName() + "')");
  firstExampleEntity.setId(txContext.getJdbcTemplate().queryForInt("SELECT LAST_INSERT_ID()"));
}

相关文章