【发布时间】:2017-03-25 17:35:08
【问题描述】:
我开始学习 Java,需要一些帮助。我需要将 CSV 文件导入 SQLite 数据库。我有这个 CSV 阅读器,但我不知道如何将这些数据复制到 SQLite 数据库中。
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
public class csv {
public static void main(String[] args) {
String csvFile = "/home/user/user.csv";
BufferedReader br = null;
String line = "";
String cvsSplitBy = ",";
try {
br = new BufferedReader(new FileReader(csvFile));
while ((line = br.readLine()) != null) {
String[] table = line.split(cvsSplitBy);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
【问题讨论】:
-
HERE: 如何打开与 SQLite 数据库的连接并插入记录。