[英]Iterate Linked List and map with the properties file value
我有country.properties
文件,其值如下:
1=USA
91=India
20=Egypt
358=Finland
33=France
679=Fiji
并具有一个响应类文件,该文件正在设置来自数据库的响应以将其显示在JSP
文件上。 我从数据库中获得的值是code
或integer
的形式。 我需要从数据库中获取该值,并且在设置响应之前,我需要使用getProperty(code)
并将该getProperty(code)
的String表示形式保存到新列表中,然后将该列表传递给setResponse
。 例如:这是我从数据库中获得的值:
col1 | col2 | col3 |
1 helo done
我需要在我的JSP页面上显示为:
col1 | col2 | col3 |
USA helo done
我正在遵循本教程http://www.mkyong.com/java/java-properties-file-examples/ 。 但无法完全了解如何实现相同目标。
这是我的DAOImpl
,我需要在其中iterate
mapped key-value
并将其保存在新列表中,然后传递到JSP
页面
public class CountDAOImpl implements IDataDAO {
private Connection conn = null;
private Statement statement = null;
private ResultSet rs = null;
private List<String> country_code = new LinkedList<String>();
//created a new list to put mapped string value instead of code
private List<String> countryMapValue = new LinkedList<String>();
public CountResponse getValue(String query) throws Exception {
CountResponse response = new CountResponse();
try {
conn = DBConnection.getInstance().getCpds().getConnection();
statement = conn.createStatement();
rs = statement.executeQuery(query);
// Extract data from result set
while (rs.next()) {
//Retrieve by column name
String cc = rs.getString("country_code");
country_code.add(cc);
}
//Setting the Response
response.setCountry(country_code);
} catch (Exception e) {
}
return response;
}
因为我是编程领域的新手,所以这方面的任何帮助都会很棒。
首先,按照此处的教程加载属性文件
... // loading properties file code here
//load a properties file from class path
prop.load(input);
然后,添加以下行以在while循环本身中指定键的情况下从属性文件中提取值-
下面的示例示例-
//Retrieve by column name
String cc = rs.getString("country_code");
country_code.add(prop.getProperty(cc));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.