Bonjour,
Je cherche une fonction equivalente avec Java DB/Derby pour lire un fichier csv en memoire comme H2
Par exemple avec H2,
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 public static void readFromCsv(String fileName) throws Exception { Map<String, String> result = new HashMap<String, String>(); ResultSet rs = Csv.getInstance().read(fileName, null, null); ResultSetMetaData meta = rs.getMetaData(); String str; while(rs.next()) { String str1 = null; String str3 = null; for(int i = 0; i < meta.getColumnCount(); i++) { // Extraire la 1ere, 3eme colonnes seleument switch(i) { case 0: str1 = rs.getString(i + 1); break; case 2: str3 = rs.getString(i + 1); break; } } if (str1 != null && str3 != null) { map.put(str1, str3); } } rs.close(); }
Partager