[英]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.