Souad
Souad

Reputation: 161

load data from file into hsqldb

how can I load data from file into hsqldb table? I have this statement that works correctly in mysql and I want to change it to work for hsqldb.

String sqlLoadkey ="load data local infile " +"'E:/Thesis/ThesisWork/outdata/keywords.txt'"+ " \n" +
            "   into table "+ "keywordsTable" +"(keywords)";
         stmt1.executeUpdate(sqlLoadkey);

this is the exception I get

java.sql.SQLSyntaxErrorException: unexpected token: LOAD
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.executeUpdate(Unknown Source)
at ThesisCode.ReductionTry.main(ReductionTry.java:67)
Exception in thread "main" java.lang.NullPointerException
at ThesisCode.ReductionTry.main(ReductionTry.java:138)

Any ideas Thanks

Upvotes: 1

Views: 2363

Answers (1)

Ivan Cachicatari
Ivan Cachicatari

Reputation: 4284

LOAD DATA is a MySQL command not valid for hsqldb, but you can use a temporary table and change the source:

-- remporary table
create table yourdb.tmp_textfiletable (col1 varchar(250));  

set table yourdb.tmp_textfiletable 
    source "'E:/Thesis/ThesisWork/outdata/keywords.txt';ignore_first=false";

-- And insert it in your normal table:

INSERT INTO yourdb.keywordsTable (keywords) 
    select Col1 from yourdb.tmp_textfiletable;

-- after that you can drop it

drop table yourdb.tmp_textfiletable

Upvotes: 1

Related Questions