Java Code Examples for org.springframework.jdbc.core.JdbcTemplate#queryForList()

The following examples show how to use org.springframework.jdbc.core.JdbcTemplate#queryForList() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MyDatabaseUpdateDao.java    From projectforge-webapp with GNU General Public License v3.0 6 votes vote down vote up
/**
 */
public List<DatabaseUpdateDO> getUpdateHistory()
{
  accessCheck(false);
  final JdbcTemplate jdbc = new JdbcTemplate(getDataSource());
  final List<Map<String, Object>> dbResult = jdbc.queryForList("select * from t_database_update order by update_date desc");
  final List<DatabaseUpdateDO> result = new ArrayList<DatabaseUpdateDO>();
  for (final Map<String, Object> map : dbResult) {
    final DatabaseUpdateDO entry = new DatabaseUpdateDO();
    entry.setUpdateDate((Date) map.get("update_date"));
    entry.setRegionId((String) map.get("region_id"));
    entry.setVersionString((String) map.get("version"));
    entry.setExecutionResult((String) map.get("execution_result"));
    final PFUserDO executedByUser = Registry.instance().getUserGroupCache().getUser((Integer) map.get("executed_by_user_fk"));
    entry.setExecutedBy(executedByUser);
    entry.setDescription((String) map.get("description"));
    result.add(entry);
  }
  return result;
}
 
Example 2
Source File: MicroMetaDao.java    From nh-micro with Apache License 2.0 6 votes vote down vote up
public List<Map<String, Object>> queryObjJoinDataByPageCondition(String innerSql, int start,int end, Object[] paramArray) {

		/*		JdbcTemplate jdbcTemplate = (JdbcTemplate) MicroDbHolder
		.getDbSource(dbName);*/
		JdbcTemplate jdbcTemplate = getMicroJdbcTemplate();
		String sql = "";
		String tempType=calcuDbType();
		if(tempType!=null && tempType.equals("mysql")){
		//if(dbType!=null && dbType.equals("mysql")){
			int pageRows=end-start;
			String limit=start+","+pageRows;
			sql=innerSql+ " limit "+limit;
		}else{
			String startLimit=" WHERE NHPAGE_RN >= "+start;
			String endLimit=" WHERE ROWNUM < "+end;
			sql="SELECT * FROM ( SELECT NHPAGE_TEMP.*, ROWNUM NHPAGE_RN FROM ("+ innerSql +" ) NHPAGE_TEMP "+endLimit+" ) "+ startLimit;
		}
		logger.debug(sql);
		logger.debug(Arrays.toString(paramArray));
		List<Map<String, Object>> retList0 = jdbcTemplate.queryForList(sql,paramArray);
		//add 201807 ning
		//List<Map<String, Object>> retList=changeOutKeyCase4List(retList0);
		//add 201902 ning
		List<Map<String, Object>> retList=ignoreKeyCase((List)retList0);		
		return retList;
	}
 
Example 3
Source File: MicroMetaDao.java    From nh-micro with Apache License 2.0 6 votes vote down vote up
public List<Map<String, Object>> queryObjJoinByCondition(String sql,Object[] paramArray) {

		/*		JdbcTemplate jdbcTemplate = (JdbcTemplate) MicroDbHolder
		.getDbSource(dbName);*/
		JdbcTemplate jdbcTemplate = getMicroJdbcTemplate();
		logger.debug(sql);
		logger.debug(Arrays.toString(paramArray));
		List<Map<String, Object>> retList0 = jdbcTemplate.queryForList(sql,paramArray);
		//add 201807 ning
		//List<Map<String, Object>> retList=changeOutKeyCase4List(retList0);
		
		//add 201902 ning
		List<Map<String, Object>> retList=ignoreKeyCase((List)retList0);
		
		return retList;
	}
 
Example 4
Source File: DynamicDBUtil.java    From jeecg with Apache License 2.0 6 votes vote down vote up
public static <T> List<T> findList(final String dbKey, String sql, Class<T> clazz,Object... param) {
	List<T> list;
	JdbcTemplate jdbcTemplate = getJdbcTemplate(dbKey);
	
	if (ArrayUtils.isEmpty(param)) {
		list = jdbcTemplate.queryForList(sql,clazz);
	} else {
		list = jdbcTemplate.queryForList(sql,clazz,param);
	}
	return list;
}
 
Example 5
Source File: ResultSetController.java    From ZenQuery with Apache License 2.0 5 votes vote down vote up
private List<Map<String, Object>> getResultRows(Integer id, String variables) {
    Query query = queryDAO.find(id);
    DatabaseConnection databaseConnection = databaseConnectionDAO.find(query.getDatabaseConnectionId());

    List<Map<String, Object>> rows = new ArrayList<Map<String, Object>>();
    try {
        BasicDataSource dataSource = dataSourceFactory.getBasicDataSource(
                databaseConnection.getUrl(),
                databaseConnection.getUsername(),
                databaseConnection.getPassword()
        );

        JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
        if (variables != null) {
            List<Object> arguments = new ArrayList<Object>();
            String[] extractedVariables = variables.split(",");

            for (String variable : extractedVariables) {
                try {
                    arguments.add(Long.parseLong(variable));
                } catch(NumberFormatException noLong) {
                    try {
                        arguments.add(Double.parseDouble(variable));
                    } catch(NumberFormatException noDouble) {
                        arguments.add(variable);
                    }
                }
            }

            rows = jdbcTemplate.queryForList(query.getContent(), arguments.toArray());
        } else {
            rows = jdbcTemplate.queryForList(query.getContent());
        }
    } catch (Exception e) {
        logger.debug(e);
    }

    return rows;
}
 
Example 6
Source File: RDBMSUtil.java    From DataLink with Apache License 2.0 5 votes vote down vote up
/**
 * 检查数据
 *
 * @param mediaSourceInfo
 * @param sql
 * @return
 */
public static List<Map<String, Object>> executeSql(MediaSourceInfo mediaSourceInfo, String sql) {

    try {
        DataSource dataSource = DataSourceFactory.getDataSource(mediaSourceInfo);
        JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
        return list;
    } catch (Exception e) {
        throw new RuntimeException("JDBC执行错误", e);
    } finally {
        DataSourceFactory.invalidate(mediaSourceInfo, () -> null);
    }

}
 
Example 7
Source File: MicroMetaDao.java    From nh-micro with Apache License 2.0 5 votes vote down vote up
public List<Map<String, Object>> queryObjByCondition(String tableName, String condition,String cols, String orders,Object[] paramArray,int[] typeArray) {
	//String tableName=changeTableNameCase(otableName);
	/*		JdbcTemplate jdbcTemplate = (JdbcTemplate) MicroDbHolder
	.getDbSource(dbName);*/
	JdbcTemplate jdbcTemplate = getMicroJdbcTemplate();
	String sql = "select "+cols+" from " + tableName + " where "+condition+" order by "+orders;
	logger.debug(sql);
	logger.debug(Arrays.toString(paramArray));
	List<Map<String, Object>> retList0 = jdbcTemplate.queryForList(sql,paramArray,typeArray);
	//add 201807 ning
	//List<Map<String, Object>> retList=changeOutKeyCase4List(retList0);	
	//add 201902 ning
	List<Map<String, Object>> retList=ignoreKeyCase((List)retList0);
	return retList;
}
 
Example 8
Source File: DynamicDBUtil.java    From teaching with Apache License 2.0 5 votes vote down vote up
public static List<Map<String, Object>> findList(final String dbKey, String sql, Object... param) {
    List<Map<String, Object>> list;
    JdbcTemplate jdbcTemplate = getJdbcTemplate(dbKey);

    if (ArrayUtils.isEmpty(param)) {
        list = jdbcTemplate.queryForList(sql);
    } else {
        list = jdbcTemplate.queryForList(sql, param);
    }
    return list;
}
 
Example 9
Source File: MultipleDataSourcesAndTransactionManagersSqlScriptsTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
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);
}
 
Example 10
Source File: InferredDataSourceSqlScriptsTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
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);
}
 
Example 11
Source File: SiteExporter.java    From lemon with Apache License 2.0 5 votes vote down vote up
public void doExport(File baseDir, JdbcTemplate jdbcTemplate,
        String siteCode) throws Exception {
    File dir = new File(baseDir, siteCode);
    dir.mkdirs();

    List<Map<String, Object>> list = jdbcTemplate
            .queryForList("select id from CMS_CATALOG");

    for (Map<String, Object> map : list) {
        String catalogId = map.get("id").toString();
        new CatalogExporter().doExport(dir, jdbcTemplate, catalogId);
    }
}
 
Example 12
Source File: InferredDataSourceTransactionalSqlScriptsTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 13
Source File: DynamicDBUtil.java    From jeecg-boot with Apache License 2.0 5 votes vote down vote up
public static <T> List<T> findList(final String dbKey, String sql, Class<T> clazz, Object... param) {
    List<T> list;
    JdbcTemplate jdbcTemplate = getJdbcTemplate(dbKey);

    if (ArrayUtils.isEmpty(param)) {
        list = jdbcTemplate.queryForList(sql, clazz);
    } else {
        list = jdbcTemplate.queryForList(sql, clazz, param);
    }
    return list;
}
 
Example 14
Source File: CatalogExporter.java    From lemon with Apache License 2.0 5 votes vote down vote up
public void exportArticles(File dir, JdbcTemplate jdbcTemplate,
        String catalogId) throws Exception {
    String sql = "select id from CMS_ARTICLE where CATALOG_ID=?";
    List<Map<String, Object>> list = jdbcTemplate.queryForList(sql,
            catalogId);

    for (Map<String, Object> map : list) {
        String articleId = map.get("id").toString();
        new ArticleExporter().doExport(dir, jdbcTemplate, articleId);
    }
}
 
Example 15
Source File: DynamicDBUtil.java    From jeecg-cloud with Apache License 2.0 5 votes vote down vote up
public static <T> List<T> findList(final String dbKey, String sql, Class<T> clazz, Object... param) {
    List<T> list;
    JdbcTemplate jdbcTemplate = getJdbcTemplate(dbKey);

    if (ArrayUtils.isEmpty(param)) {
        list = jdbcTemplate.queryForList(sql, clazz);
    } else {
        list = jdbcTemplate.queryForList(sql, clazz, param);
    }
    return list;
}
 
Example 16
Source File: MicroMetaDao.java    From nh-micro with Apache License 2.0 5 votes vote down vote up
public List<Map<String, Object>> queryObjByCondition(String tableName, String condition,String cols, String orders,Object[] paramArray) {
	//String tableName=changeTableNameCase(otableName);
	/*		JdbcTemplate jdbcTemplate = (JdbcTemplate) MicroDbHolder
	.getDbSource(dbName);*/
	JdbcTemplate jdbcTemplate = getMicroJdbcTemplate();
	String sql = "select "+cols+" from " + tableName + " where "+condition+" order by "+orders;
	logger.debug(sql);
	logger.debug(Arrays.toString(paramArray));
	List<Map<String, Object>> retList0 = jdbcTemplate.queryForList(sql,paramArray);
	//add 201807 ning
	//List<Map<String, Object>> retList=changeOutKeyCase4List(retList0);	
	//add 201902 ning
	List<Map<String, Object>> retList=ignoreKeyCase((List)retList0);
	return retList;
}
 
Example 17
Source File: MicroMetaDao.java    From nh-micro with Apache License 2.0 5 votes vote down vote up
public List<MicroMetaBean> queryMetaBeanByCondition(String tableName, String condition,Object[] paramArray,int[] typeArray) {
	List<MicroMetaBean> retBeanList=new ArrayList();
	/*		JdbcTemplate jdbcTemplate = (JdbcTemplate) MicroDbHolder
	.getDbSource(dbName);*/
	JdbcTemplate jdbcTemplate = getMicroJdbcTemplate();
	String sql = "select * from " + tableName + " where "+condition;
	logger.debug(sql);
	logger.debug(Arrays.toString(paramArray));
	List<Map<String, Object>> retList = jdbcTemplate.queryForList(sql,paramArray,typeArray);
	if(retList==null){
		return retBeanList;
	}
	
	for(Map<String,Object> rowMap:retList){
		MicroMetaBean metaBean = new MicroMetaBean();
		metaBean.setId((String) rowMap.get("id"));
		metaBean.setMeta_content((String) rowMap.get("meta_content"));
		metaBean.setMeta_key((String) rowMap.get("meta_key"));
		metaBean.setMeta_name((String) rowMap.get("meta_name"));
		metaBean.setMeta_type((String) rowMap.get("meta_type"));
		metaBean.setRemark((String) rowMap.get("remark"));
		metaBean.setCreate_time((Date) rowMap.get("create_time"));
		metaBean.setUpdate_time((Date) rowMap.get("update_time"));
		retBeanList.add(metaBean);
	}
	return retBeanList;
}
 
Example 18
Source File: InferredDataSourceTransactionalSqlScriptsTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
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);
}
 
Example 19
Source File: DynamicDBUtil.java    From jeecg with Apache License 2.0 5 votes vote down vote up
public static List<Map<String, Object>> findList(final String dbKey, String sql, Object... param) {
	List<Map<String, Object>> list;
	JdbcTemplate jdbcTemplate = getJdbcTemplate(dbKey);
	
	if (ArrayUtils.isEmpty(param)) {
		list = jdbcTemplate.queryForList(sql);
	} else {
		list = jdbcTemplate.queryForList(sql, param);
	}
	return list;
}
 
Example 20
Source File: InferredDataSourceSqlScriptsTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
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);
}