Is there simpler way to convert CSV files to SQL file than this?:
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();
}
If you don’t find a simpler solution be wary of doing a simple split on csv data. Speaking from experience this is valid csv that will break a simple split solution:
I would suggest looking at a library such as opencsv to handle csv parsing for you.