Loading a Flat File to a MySQL Table, file is terminated by \r\n, use this statement
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
public class Main {
public static void main(String[] argv) throws Exception {
Connection connection = DriverManager.getConnection(url, username, password);
Statement stmt = connection.createStatement();
// Load the data
String filename = "c:/infile.txt";
String tablename = "mysql_2_table";
stmt.executeUpdate("LOAD DATA INFILE \"" + filename + "\" INTO TABLE " + tablename);
// file is terminated by \r\n, use this statement
stmt.executeUpdate("LOAD DATA INFILE \"" + filename + "\" INTO TABLE "
+ tablename + " LINES TERMINATED BY '\\r\\n'");
}
}
Related examples in the same category