本文整理匯總了Java中org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.queryForList方法的典型用法代碼示例。如果您正苦於以下問題:Java NamedParameterJdbcTemplate.queryForList方法的具體用法?Java NamedParameterJdbcTemplate.queryForList怎麽用?Java NamedParameterJdbcTemplate.queryForList使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate
的用法示例。
在下文中一共展示了NamedParameterJdbcTemplate.queryForList方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: assignData
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; //導入方法依賴的package包/類
private static void assignData(LineageNodeLite node) {
List<Map<String, Object>> rows = null;
MapSqlParameterSource parameters = new MapSqlParameterSource();
parameters.addValue("urn", node.urn);
NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(getJdbcTemplate().getDataSource());
rows = namedParameterJdbcTemplate.queryForList(GET_DATA_ATTR, parameters);
for (Map<String, Object> row : rows) {
// node only knows id, level, and urn, assign all other attributes
JsonNode prop = Json.parse((String) row.get("properties"));
node.description = (prop.has("description")) ? prop.get("description").asText() : "null";
node.source = (String) row.get("source");
node.storage_type = (String) row.get("dataset_type"); // what the js calls storage_type, the sql calls dataset_type
node.dataset_type = (String) row.get("dataset_type");
// check wh_property for a user specified color, use some generic defaults if nothing found
//node.color = getColor(node.urn, node.node_type);
//node.abstracted_path = getPostfix(node.urn);
// set things to show up in tooltip
node._sort_list.add("abstracted_path");
node._sort_list.add("storage_type");
}
}
示例2: getTableNames
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; //導入方法依賴的package包/類
public static List<String> getTableNames(String scopes)
{
//Logger.debug("Entering AdvSearch.java:getTableNames()");
List<String> tables = null;
if (StringUtils.isNotBlank(scopes))
{
String[] scopeArray = scopes.split(",");
List<String> scopeList = Arrays.asList(scopeArray);
Map<String, List> param = Collections.singletonMap("scopes", scopeList);
NamedParameterJdbcTemplate namedParameterJdbcTemplate = new
NamedParameterJdbcTemplate(getJdbcTemplate().getDataSource());
tables = namedParameterJdbcTemplate.queryForList(
GET_DATASET_TABLE_NAMES_BY_SCOPE, param, String.class);
}
else
{
tables = getJdbcTemplate().queryForList(GET_DATASET_TABLE_NAMES, String.class);
}
return tables;
}
示例3: getFlowNames
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; //導入方法依賴的package包/類
public static List<String> getFlowNames(String applications)
{
//ogger.debug("Entering AdvSearch.java:getFlowNames()");
List<String> flowNames = null;
if (StringUtils.isNotBlank(applications))
{
String[] appArray = applications.split(",");
List<String> appList = Arrays.asList(appArray);
Map<String, List> param = Collections.singletonMap("apps", appList);
NamedParameterJdbcTemplate namedParameterJdbcTemplate = new
NamedParameterJdbcTemplate(getJdbcTemplate().getDataSource());
flowNames = namedParameterJdbcTemplate.queryForList(
GET_FLOW_NAMES_BY_APP, param, String.class);
}
else
{
flowNames = getJdbcTemplate().queryForList(GET_FLOW_NAMES, String.class);
}
return flowNames;
}
示例4: assignApp
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; //導入方法依賴的package包/類
private static void assignApp(LineageNodeLite node) {
List<Map<String, Object>> rows = null;
MapSqlParameterSource parameters = new MapSqlParameterSource();
parameters.addValue("urn", node.urn);
NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(getJdbcTemplate().getDataSource());
rows = namedParameterJdbcTemplate.queryForList(GET_DATA_ATTR, parameters);
for (Map<String, Object> row : rows) {
// node only knows id, level, and urn, assign all other attributes
// stored in dict_dataset, so has those fields
JsonNode prop = Json.parse((String) row.get("properties"));
// properties is a JsonNode, extract what we want out of it
node.description = (prop.has("description")) ? prop.get("description").asText() : "null";
node.app_code = (prop.has("app_code")) ? prop.get("app_code").asText() : "null";
// check wh_property for a user specified color, use some generic defaults if nothing found
//node.color = getColor(node.urn, node.node_type);
// set things to show up in tooltip
node._sort_list.add("app_code");
node._sort_list.add("description");
}
}
示例5: assignDB
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; //導入方法依賴的package包/類
private static void assignDB(LineageNodeLite node) {
List<Map<String, Object>> rows = null;
MapSqlParameterSource parameters = new MapSqlParameterSource();
parameters.addValue("urn", node.urn);
NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(getJdbcTemplate().getDataSource());
rows = namedParameterJdbcTemplate.queryForList(GET_DATA_ATTR, parameters);
// node only knows id, level, and urn, assign all other attributes
for (Map<String, Object> row : rows) {
JsonNode prop = Json.parse((String) row.get("properties"));
node.description = (prop.has("description")) ? prop.get("description").asText() : "null";
node.jdbc_url = (prop.has("jdbc_url")) ? prop.get("jdbc_url").asText() : "null";
node.db_code = (prop.has("db_code")) ? prop.get("db_code").asText() : "null";
// check wh_property for a user specified color, use some generic defaults if nothing found
//node.color = getColor(node.urn, node.node_type);
// set things to show up in tooltip
node._sort_list.add("db_code");
//node._sort_list.add("last_modified");
}
}
示例6: assignGeneral
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; //導入方法依賴的package包/類
private static void assignGeneral(LineageNodeLite node) {
List<Map<String, Object>> rows = null;
MapSqlParameterSource parameters = new MapSqlParameterSource();
parameters.addValue("urn", node.urn);
NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(getJdbcTemplate().getDataSource());
rows = namedParameterJdbcTemplate.queryForList(GET_DATA_ATTR, parameters);
for (Map<String, Object> row : rows) {
node.name = (String) row.get("name");
node.schema = (String) row.get("schema");
// check wh_property for a user specified color, use some generic defaults if nothing found
node.color = getNodeColor(node.urn, node.node_type);
// set things to show up in tooltip
node._sort_list.add("urn");
node._sort_list.add("name");
}
}
示例7: getTableNames
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; //導入方法依賴的package包/類
public static List<String> getTableNames(String scopes)
{
List<String> tables = null;
if (StringUtils.isNotBlank(scopes))
{
String[] scopeArray = scopes.split(",");
List<String> scopeList = Arrays.asList(scopeArray);
Map<String, List> param = Collections.singletonMap("scopes", scopeList);
NamedParameterJdbcTemplate namedParameterJdbcTemplate = new
NamedParameterJdbcTemplate(getJdbcTemplate().getDataSource());
tables = namedParameterJdbcTemplate.queryForList(
GET_DATASET_TABLE_NAMES_BY_SCOPE, param, String.class);
}
else
{
tables = getJdbcTemplate().queryForList(GET_DATASET_TABLE_NAMES, String.class);
}
return tables;
}
示例8: getFlowNames
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; //導入方法依賴的package包/類
public static List<String> getFlowNames(String applications)
{
List<String> flowNames = null;
if (StringUtils.isNotBlank(applications))
{
String[] appArray = applications.split(",");
List<String> appList = Arrays.asList(appArray);
Map<String, List> param = Collections.singletonMap("apps", appList);
NamedParameterJdbcTemplate namedParameterJdbcTemplate = new
NamedParameterJdbcTemplate(getJdbcTemplate().getDataSource());
flowNames = namedParameterJdbcTemplate.queryForList(
GET_FLOW_NAMES_BY_APP, param, String.class);
}
else
{
flowNames = getJdbcTemplate().queryForList(GET_FLOW_NAMES, String.class);
}
return flowNames;
}
示例9: zoekIdsPersoonMetBsn
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; //導入方法依賴的package包/類
@Override
public List<Long> zoekIdsPersoonMetBsn(final String bsn) {
final String sql = "SELECT id FROM kern.pers persoon WHERE persoon.bsn = :bsn AND persoon.srt = 1";
final NamedParameterJdbcTemplate jdbcTemplate = new NamedParameterJdbcTemplate(masterDataSource);
final Map<String, Object> parameters = new HashMap<>(1, 1);
parameters.put("bsn", bsn);
return jdbcTemplate.queryForList(sql, parameters, Long.class);
}
示例10: zoekIdsPersoonMetAnummer
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; //導入方法依賴的package包/類
@Override
public List<Long> zoekIdsPersoonMetAnummer(final String anr) {
final String sql = "SELECT id FROM kern.pers persoon WHERE persoon.anr = :anr AND persoon.srt = 1";
final NamedParameterJdbcTemplate jdbcTemplate = new NamedParameterJdbcTemplate(masterDataSource);
final Map<String, Object> parameters = new HashMap<>(1, 1);
parameters.put("anr", anr);
return jdbcTemplate.queryForList(sql, parameters, Long.class);
}
示例11: processCsvText
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; //導入方法依賴的package包/類
private static String processCsvText(ExportDataConfig config, NamedParameterJdbcTemplate jdbcTemplate,
Map<String, Object> sqlParamMap) throws Exception {
logger.info("export-Id: " + config.getId() + " name: " + config.getName());
StringBuilder out = new StringBuilder();
out.append(config.getTitle()).append("\r\n");
List<Map<String, Object>> results = jdbcTemplate.queryForList(config.getSql(), sqlParamMap);
for (int i=0; results!=null && i<results.size(); i++) {
Map<String, Object> dataMap = results.get(i);
for (Map.Entry<String, Object> entry : dataMap.entrySet()) {
if ( entry.getValue() != null ) {
String str = "";
if (entry.getValue() instanceof byte[]) { // blob text
str = new String( (byte[])entry.getValue() , Constants.BASE_ENCODING );
} else {
str = String.valueOf( entry.getValue() );
}
if (config.isEscapeCsv()) {
//str = StringEscapeUtils.escapeCsv(str);
str = SimpleUtils.escapeCsv(str);
}
if (StringUtils.isBlank(str)) {
str = " ";
}
out.append("\"").append(str).append("\"");
} else {
out.append(" ");
}
out.append( config.getSeparateSymbol() );
}
out.append("\r\n");
}
return out.toString();
}
示例12: copy
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; //導入方法依賴的package包/類
private void copy() {
/** GG CONSIDER FOR DEST SOMEGHINT LIKE
* import org.h2.jdbcx.JdbcConnectionPool;
JdbcConnectionPool cp = JdbcConnectionPool.
create("jdbc:h2:~/test", "sa", "sa");
Connection conn = cp.getConnection();
conn.close(); cp.dispose();
java -cp 'C:\Users\giorgig\.m2\repository\com\h2database\h2\1.4.188\h2-1.4.188.jar' org.h2.tools.Shell -url jdbc:h2:./dump_8-set-2015.db
*/
logger.warn("How to populate an empty db with !SmartSync!");
try
{
// create a database connection.
b.setSource(getSrcDs());
b.setDestination(getDestDs());
//b.addTables("PERSON");
NamedParameterJdbcTemplate t=new NamedParameterJdbcTemplate(getSrcDs());
// public <T> List<T> queryForList(String sql, Map<String, ?> paramMap, Class<T> elementType)
List<String> tables= t.queryForList(this.extractQuery, new TreeMap<String, Object>(), String.class);
b.addTables(tables);
logger.info("Db1 and db2 ready. Demo sync db1->db2");
b.syncAll();
logger.info("Ends here");
}
catch(Throwable e)
{
logger.fatal("ERROR",e);
}
finally
{
}
}
示例13: copy
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; //導入方法依賴的package包/類
public void copy() {
logger.warn("How to populate an empty db with !SmartSync!");
try
{
// create a database connection. Exmple of in memory
SmartSyncPump b=new SQLitePump();
b.setSource(getSrcDs());
b.setDestination(getDestDs());
//b.addTables("PERSON");
NamedParameterJdbcTemplate t=new NamedParameterJdbcTemplate(getSrcDs());
// public <T> List<T> queryForList(String sql, Map<String, ?> paramMap, Class<T> elementType)
final List<String> tables;
if(tableList==null){
tables= t.queryForList(this.extractQuery, new TreeMap<String, Object>(), String.class);
}else{
tables=tableList;
}
b.addTables(tables);
logger.info("Db1 and db2 ready. Demo sync db1->db2");
b.syncAll();
logger.info("Ends here");
}
catch(Throwable e)
{
logger.fatal("ERROR",e);
}
finally
{
}
}
示例14: assignPrefs
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; //導入方法依賴的package包/類
private static Boolean assignPrefs(LineageNodeLite node) {
// first try to get property list
String properties = getProp("prop." + getPrefix(node.urn));
if (properties == "default") {
//Logger.info("no properties for " + getPrefix(node.urn));
properties = getProp("prop." + node.node_type);
if (properties == "default") {
//Logger.info("no properties for " + node.node_type);
return false;
}
}
List<String> propList = Arrays.asList(properties.split(","));
//Logger.debug("propList: " + propList);
// now get all the values that dict_dataset has
List<Map<String, Object>> rows = null;
MapSqlParameterSource parameters = new MapSqlParameterSource();
parameters.addValue("urn", node.urn);
NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(getJdbcTemplate().getDataSource());
rows = namedParameterJdbcTemplate.queryForList(GET_DATA_ATTR, parameters);
for (Map<String, Object> row : rows) {
JsonNode prop = Json.parse((String) row.get("properties"));
for (String p : propList) {
try {
if (p.substring(0, 5).equals("prop/")) {
if (prop != null && prop.has(p.substring(5))) {
node.setStringField(p.substring(5), prop.get(p.substring(5)).asText());
}
} else {
node.setStringField(p, (String) row.get(p));
}
} catch (NoSuchFieldException fe) {
Logger.error("field " + p + " is non exsistant");
} catch (IllegalAccessException e) {
Logger.error("field " + p + " is private");
}
}
}
String sortsattr = getProp("prop.sortlist." + getPrefix(node.urn));
if (sortsattr == "default") {
//Logger.info("no sortlist for " + getPrefix(node.urn));
sortsattr = getProp("prop.sortlist." + node.node_type);
if (sortsattr == "default") {
//Logger.info("no sortlist for " + node.node_type);
return false;
}
}
List<String> sortList = Arrays.asList(sortsattr.split(","));
Logger.trace("sortList: " + sortList);
for (String sl : sortList) {
node._sort_list.add(sl);
}
return true;
}
示例15: previewData
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; //導入方法依賴的package包/類
public void previewData(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String sql=req.getParameter("sql");
String parameters=req.getParameter("parameters");
Map<String, Object> map = buildParameters(parameters);
sql=parseSql(sql, map);
Connection conn=null;
try{
conn=buildConnection(req);
List<Map<String,Object>> list=null;
if(ProcedureUtils.isProcedure(sql)){
list=ProcedureUtils.procedureQuery(sql, map, conn);
}else{
DataSource dataSource=new SingleConnectionDataSource(conn,false);
NamedParameterJdbcTemplate jdbc=new NamedParameterJdbcTemplate(dataSource);
list=jdbc.queryForList(sql, map);
}
int size=list.size();
int currentTotal=size;
if(currentTotal>500){
currentTotal=500;
}
List<Map<String,Object>> ls=new ArrayList<Map<String,Object>>();
for(int i=0;i<currentTotal;i++){
ls.add(list.get(i));
}
DataResult result=new DataResult();
List<String> fields=new ArrayList<String>();
if(size>0){
Map<String,Object> item=list.get(0);
for(String name:item.keySet()){
fields.add(name);
}
}
result.setFields(fields);
result.setCurrentTotal(currentTotal);
result.setData(ls);
result.setTotal(size);
writeObjectToJson(resp, result);
}catch(Exception ex){
throw new ServletException(ex);
}finally{
if(conn!=null){
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}