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

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

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

JdbcTemplate.queryForList介绍

暂无

代码示例

代码示例来源:origin: alibaba/nacos

public List<String> getTenantIdList(int page, int pageSize) {
  String sql = "SELECT tenant_id FROM config_info WHERE tenant_id != '' GROUP BY tenant_id LIMIT ?, ?";
  int from = (page - 1) * pageSize;
  return jt.queryForList(sql, String.class, from, pageSize);
}

代码示例来源:origin: alibaba/nacos

public List<String> getGroupIdList(int page, int pageSize) {
  String sql = "SELECT group_id FROM config_info WHERE tenant_id ='' GROUP BY group_id LIMIT ?, ?";
  int from = (page - 1) * pageSize;
  return jt.queryForList(sql, String.class, from, pageSize);
}

代码示例来源:origin: spring-projects/spring-framework

@Override
  public void afterPropertiesSet() throws Exception {
    cache = jdbcTemplate.queryForList("SELECT * FROM T_TEST");
  }
}

代码示例来源:origin: spring-projects/spring-security

public boolean userExists(String username) {
  List<String> users = getJdbcTemplate().queryForList(userExistsSql,
      new String[] { username }, String.class);
  if (users.size() > 1) {
    throw new IncorrectResultSizeDataAccessException(
        "More than one user found with name '" + username + "'", 1);
  }
  return users.size() == 1;
}

代码示例来源:origin: spring-projects/spring-framework

private void assertUsers(JdbcTemplate jdbcTemplate, String... users) {
  List<String> expected = Arrays.asList(users);
  Collections.sort(expected);
  List<String> actual = jdbcTemplate.queryForList("select name from user", String.class);
  Collections.sort(actual);
  assertEquals("Users in database;", expected, actual);
}

代码示例来源:origin: spring-projects/spring-framework

private void assertUsers(JdbcTemplate jdbcTemplate, String... users) {
  List<String> expected = Arrays.asList(users);
  Collections.sort(expected);
  List<String> actual = jdbcTemplate.queryForList("select name from user", String.class);
  Collections.sort(actual);
  assertEquals("Users in database;", expected, actual);
}

代码示例来源:origin: spring-projects/spring-framework

private void assertUsers(String... users) {
  List<String> expected = Arrays.asList(users);
  Collections.sort(expected);
  List<String> actual = jdbcTemplate.queryForList("select name from user", String.class);
  Collections.sort(actual);
  assertEquals("Users in database;", expected, actual);
}

代码示例来源:origin: spring-projects/spring-framework

private void assertUsers(JdbcTemplate jdbcTemplate, String... users) {
  List<String> expected = Arrays.asList(users);
  Collections.sort(expected);
  List<String> actual = jdbcTemplate.queryForList("select name from user", String.class);
  Collections.sort(actual);
  assertEquals("Users in database;", expected, actual);
}

代码示例来源:origin: spring-projects/spring-framework

private void assertUsers(JdbcTemplate jdbcTemplate, String... users) {
  List<String> expected = Arrays.asList(users);
  Collections.sort(expected);
  List<String> actual = jdbcTemplate.queryForList("select name from user", String.class);
  Collections.sort(actual);
  assertEquals("Users in database;", expected, actual);
}

代码示例来源:origin: spring-projects/spring-framework

private void assertUsers(String... users) {
  List<String> expected = Arrays.asList(users);
  Collections.sort(expected);
  List<String> actual = jdbcTemplate.queryForList("select name from user", String.class);
  Collections.sort(actual);
  assertEquals("Users in database;", expected, actual);
}

代码示例来源:origin: spring-projects/spring-framework

private void doTestQueryForListWithArgs(String sql) throws Exception {
  given(this.resultSet.next()).willReturn(true, true, false);
  given(this.resultSet.getObject(1)).willReturn(11, 12);
  List<Map<String, Object>> li = this.template.queryForList(sql, new Object[] {3});
  assertEquals("All rows returned", 2, li.size());
  assertEquals("First row is Integer", 11, ((Integer) li.get(0).get("age")).intValue());
  assertEquals("Second row is Integer", 12, ((Integer) li.get(1).get("age")).intValue());
  verify(this.preparedStatement).setObject(1, 3);
  verify(this.resultSet).close();
  verify(this.preparedStatement).close();
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void testQueryForList() throws Exception {
  String sql = "SELECT AGE FROM CUSTMR WHERE ID < 3";
  given(this.resultSet.next()).willReturn(true, true, false);
  given(this.resultSet.getObject(1)).willReturn(11, 12);
  List<Map<String, Object>> li = this.template.queryForList(sql);
  assertEquals("All rows returned", 2, li.size());
  assertEquals("First row is Integer", 11, ((Integer) li.get(0).get("age")).intValue());
  assertEquals("Second row is Integer", 12, ((Integer) li.get(1).get("age")).intValue());
  verify(this.resultSet).close();
  verify(this.statement).close();
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void testQueryForListWithSingleRowAndColumn() throws Exception {
  String sql = "SELECT AGE FROM CUSTMR WHERE ID < 3";
  given(this.resultSet.next()).willReturn(true, false);
  given(this.resultSet.getObject(1)).willReturn(11);
  List<Map<String, Object>> li = this.template.queryForList(sql);
  assertEquals("All rows returned", 1, li.size());
  assertEquals("First row is Integer", 11, ((Integer) li.get(0).get("age")).intValue());
  verify(this.resultSet).close();
  verify(this.statement).close();
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void testQueryForListWithEmptyResult() throws Exception {
  String sql = "SELECT AGE FROM CUSTMR WHERE ID < 3";
  given(this.resultSet.next()).willReturn(false);
  List<Map<String, Object>> li = this.template.queryForList(sql);
  assertEquals("All rows returned", 0, li.size());
  verify(this.resultSet).close();
  verify(this.statement).close();
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * SPR-6038: detect HSQL and stop illegal locks being taken.
 * TODO: Against Quartz 2.2, this test's job doesn't actually execute anymore...
 */
@Test
public void schedulerWithHsqlDataSource() throws Exception {
  // Assume.group(TestGroup.PERFORMANCE);
  DummyJob.param = 0;
  DummyJob.count = 0;
  ClassPathXmlApplicationContext ctx = context("databasePersistence.xml");
  JdbcTemplate jdbcTemplate = new JdbcTemplate(ctx.getBean(DataSource.class));
  assertFalse("No triggers were persisted", jdbcTemplate.queryForList("SELECT * FROM qrtz_triggers").isEmpty());
  /*
  Thread.sleep(3000);
  try {
    assertTrue("DummyJob should have been executed at least once.", DummyJob.count > 0);
  }
  finally {
    ctx.close();
  }
  */
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void testQueryForListWithArgsAndSingleRowAndColumn() throws Exception {
  String sql = "SELECT AGE FROM CUSTMR WHERE ID < ?";
  given(this.resultSet.next()).willReturn(true, false);
  given(this.resultSet.getObject(1)).willReturn(11);
  List<Map<String, Object>> li = this.template.queryForList(sql, new Object[] {3});
  assertEquals("All rows returned", 1, li.size());
  assertEquals("First row is Integer", 11, ((Integer) li.get(0).get("age")).intValue());
  verify(this.preparedStatement).setObject(1, 3);
  verify(this.resultSet).close();
  verify(this.preparedStatement).close();
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void testQueryForListWithArgsAndEmptyResult() throws Exception {
  String sql = "SELECT AGE FROM CUSTMR WHERE ID < ?";
  given(this.resultSet.next()).willReturn(false);
  List<Map<String, Object>> li = this.template.queryForList(sql, new Object[] {3});
  assertEquals("All rows returned", 0, li.size());
  verify(this.preparedStatement).setObject(1, 3);
  verify(this.resultSet).close();
  verify(this.preparedStatement).close();
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void testQueryForListWithIntegerElement() throws Exception {
  String sql = "SELECT AGE FROM CUSTMR WHERE ID < 3";
  given(this.resultSet.next()).willReturn(true, false);
  given(this.resultSet.getInt(1)).willReturn(11);
  List<Integer> li = this.template.queryForList(sql, Integer.class);
  assertEquals("All rows returned", 1, li.size());
  assertEquals("Element is Integer", 11, li.get(0).intValue());
  verify(this.resultSet).close();
  verify(this.statement).close();
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void testQueryForListWithArgsAndIntegerElementAndSingleRowAndColumn() throws Exception {
  String sql = "SELECT AGE FROM CUSTMR WHERE ID < ?";
  given(this.resultSet.next()).willReturn(true, false);
  given(this.resultSet.getInt(1)).willReturn(11);
  List<Integer> li = this.template.queryForList(sql, new Object[] {3}, Integer.class);
  assertEquals("All rows returned", 1, li.size());
  assertEquals("First row is Integer", 11, li.get(0).intValue());
  verify(this.preparedStatement).setObject(1, 3);
  verify(this.resultSet).close();
  verify(this.preparedStatement).close();
}

代码示例来源:origin: spring-projects/spring-security

@Test
public void createUserDoesNotSaveAuthoritiesIfEnableAuthoritiesIsFalse()
    throws Exception {
  manager.setEnableAuthorities(false);
  manager.createUser(joe);
  assertThat(template.queryForList(SELECT_JOE_AUTHORITIES_SQL)).isEmpty();
}

相关文章