public class MysqlTest {
static String driver = "com.mysql.jdbc.Driver";
static String url = "jdbc:mysql://10.119.8.67:3306/test_data?useSSL=false";
static Connection conn = null;
public static void main(String[] args){
System.out.println("MysqlTest main start");
try {
Class.forName(driver);
conn = DriverManager.getConnection(url, "root", "Qwe@1234");
String sql = "load data local infile \'E:\\\\work\\\\scala\\\\test\\\\cellNew0502.txt\' into table cell fields terminated by '|';";
System.out.println("MysqlTest main sql " + sql );
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.execute();
conn.close();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
System.out.println("MysqlTest main end");
}
使用load data 插入数据效率非常快。