2016-09-15 5 views
0

私はJavaを使用してHSSQLデータベースにCSVデータをインポートしようとしていますし、このSQL文:はによって引き起こさ:org.hsqldb.HsqlException:無効statemnet - CSVデータをインポートするときに、テキストテーブルが必要

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 

PS HSSQLクライアントでこれを使用すると、うまく動作します。

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

答えて

1

バックスラッシュを2回エスケープする必要があります。次のコードは例外を示していません。

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(); 
} 
+0

これはあまりにも悪いですが、これはうまくいきません。 – zygimantus

+0

@zygimantusは私の答えを編集しました。コードを実行するときにどんなエラーが発生しますか?私のために働くと思われる。 – Guenther

+0

どのバージョンのhsqldbを使用しましたか?私は2.3.4を使用しています – zygimantus

関連する問題