引起:org.hsqldb.HsqlException:无效的statemnet - 导入CSV数据时需要的文本表

时间:2016-09-15 06:34:38

标签: java hsqldb hypersql

我正在尝试使用java和这个SQL语句将CSV数据导入HSSQL数据库:

statement.execute("set TABLE data_source source 'data.csv;ignore_first=true;fs=\\semi'");

但是我收到了这个错误:

Exception in thread "main" java.sql.SQLException: invalid statemnet - text table required in statement [set TABLE data_source source 'data.csv;ignore_first=true;fs=\semi']
    at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
    at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
    at org.hsqldb.jdbc.JDBCStatement.fetchResult(Unknown Source)
    at org.hsqldb.jdbc.JDBCStatement.execute(Unknown Source)
    at com.test.Application.main(Application.java:53)
Caused by: org.hsqldb.HsqlException: invalid statemnet - text table required
    at org.hsqldb.error.Error.error(Unknown Source)
    at org.hsqldb.error.Error.error(Unknown Source)
    at org.hsqldb.StatementCommand.getResult(Unknown Source)
    at org.hsqldb.StatementCommand.execute(Unknown Source)
    at org.hsqldb.Session.executeCompiledStatement(Unknown Source)
    at org.hsqldb.Session.executeDirectStatement(Unknown Source)
    at org.hsqldb.Session.execute(Unknown Source)
    ... 3 more

P.S。在HSSQL客户端中使用它可以正常工作:

set TABLE data_source source 'data.csv;ignore_first=true;fs=\semi'

1 个答案:

答案 0 :(得分:1)

你需要两次逃避反斜杠。以下代码未显示任何例外情况。

public static void main(String[] args) throws Exception {
    Connection connection = DriverManager.getConnection("jdbc:hsqldb:file:~/swdev/hsqldb/testdb", "SA", "");
    PreparedStatement statement = connection.prepareCall("create text TABLE data_source (id INTEGER)");
    statement.execute();
    statement.close();
    statement = connection.prepareCall("set TABLE data_source source 'data.csv;ignore_first=true;fs=\\\\semi'");
    statement.execute();
    statement.close();
    connection.close();
}