今天测试JDBC Connection使用Load Data InFile往数据表中导入数据,Java程序如下:
public class LoadDataTest {
@Test
public void test_loadData() throws Exception {
Connection conn = null;
Statement stmt = null;
try {
conn = DBUtils.fetchConnection();
stmt = conn.createStatement();
String sql = "load data infile 'c:/test_key_value.txt' into table test_key_value fields terminated by ',' enclosed by '\'' lines terminated by '\r\n'";
boolean result = stmt.execute(sql);
System.out.println("Load执行结果:" + result);
} finally {
DBUtils.freeConnection();
DBUtils.closeQuietly(stmt);
DBUtils.closeDataSource();
}
}
}
可是一直报MySQL语法异常:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''' at line 2
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at c