我有一個獨立的應用程序,它連接到SQL數據庫並將ResultSet保存在Map列表中。這是我到目前爲止:將地圖列表寫入CSV
List<Map<String, Object>> rows;
stmt = conn.createStatement();
Resultset rs = stmt.executeQuery(queryString);
ResultSetMetaData rsmd; //Properties of Resultset object and column count
while(rs.next){
Map<String, Object> rowResult = new HashMap<String, Object>(columnCount);
for(int i =1; i <=columnCount; i++){
rowResult.put(rsmd.getColumnName(i), rs.getObject(i));
}
rows.add(rowResult);
}
//WRITE TO CSV
String csv = "C:\\Temp\\data.csv";
CSVWriter writer = new CSVWriter(new FileWriter(csv));
//Write the record to file
writer.writeNext(rows);
//close the writer
writer.close();
如何將列的這些「行」添加到帶有列的csv?任何線索和建議。感謝您的幫助。
你說你很難將列表保存到文件中。你有什麼嘗試? –
我正在關注這個例子@MichaelMarkidis:http://stackoverflow.com/questions/31172003/java-write-hashmap-to-a-csv-file – user2501165
你想使用庫嗎?你能顯示你在你的問題中嘗試過的代碼嗎? –