我正在尝试在Java中运行以下语句,并且在执行@dummy作为代码的一部分时,我遇到了MySQL语法错误。我使用@dummy作为SQL语句的一部分,以跳过从csv文件导入的某些不需要的列。当我在MySQL中执行SQL语句时,同样的语句工作正常,但在Java中的@符号处失败。以下是我尝试运行的代码示例...
String url = "jdbc:mysql://localhost:3306/databasename";
String username = "username";
String password = "password";
java.sql.Connection connection = null;
try {
System.out.println("Connecting database...");
connection = DriverManager.getConnection(url, username, password);
System.out.println("Database connected!");
java.sql.Statement stmt = connection.createStatement();
int rss = stmt.executeUpdate(
"LOAD DATA LOCAL INFILE 'C:/downloads/test.csv' INTO TABLE test"
+ "FIELDS TERMINATED BY ','"
+ "ENCLOSED BY '\"'"
+ "LINES TERMINATED BY '\\n'"
+ "IGNORE 1 LINES"
+ "(Id,Title,@dummy,Issue,Project)"
+ "SET Project = ('Test');"
);
} catch (SQLException e) {
throw new RuntimeException("Cannot connect the database!", e);
} finally {
System.out.println("Closing the connection.");
if (connection != null) try { connection.close(); } catch (SQLException ignore) {}
}
我不确定Java编译器是否看到" @"作为注释或完全不同的东西,但我一直无法找到有关此问题的任何信息。
以下是我收到的错误消息......
引起:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 您的SQL语法有错误;检查手册 对应于您的MySQL服务器版本,以便使用正确的语法 靠近'终止于'''' ' \ n' IGNORE 1 LINES(Id,Title,' at line 1
感谢您的帮助!