有沒有簡單的CSV文件轉換爲SQL文件的方式比這?:簡單的CSV到SQL的Java文件轉換器
BufferedReader input = new BufferedReader(new FileReader(new File("c:\\file.csv")));
Writer output = new BufferedWriter(new FileWriter(new File("c:\\file.sql")));
try {
String line = null;
String[] st = null;
while ((line = input.readLine()) != null) {
st = line.replace("\"","").split(",");
output.write("INSERT INTO `table` "
+ "(`column_id`, `column1`, `column2`) VALUES "
+ "(" + st[2] + ", " + st[0] + ", " + st[1] +")"
+ ";"
+ "COMMIT;\n");
}
} finally {
input.close();
output.close();
}
@Asaph:最多支持CSV導入=) – 2010-11-17 04:44:46
您使用的數據庫是?它是MySQL嗎?如果是這樣,您可以使用一些熟練撥打的選項,通過'LOAD DATA INFILE'導入CSV文件。 – Asaph 2010-11-17 04:44:58