设置文本表hsqldb Java

时间:2014-06-03 09:16:10

标签: java file hsqldb

我正在尝试创建一个文本表,从文件中设置其值,然后使用Java代码中的hsqldb将这些值插回到普通表中,如下代码所示:

String sqlkeywordcreate=new String ("CREATE TABLE keywordsTable " + " (k_id INTEGER IDENTITY not NULL PRIMARY KEY,  keywords varchar(20))");
        String sqlkeywordcreate1=new String ("CREATE TEXT TABLE tempKeywordsTable " + " (key varchar(20))");
        System.out.println(sqlkeywordcreate);
        stmt1.executeUpdate(sqlkeywordcreate);
        stmt1.executeUpdate(sqlkeywordcreate1);
        int numOfFields=di.getAllTerms(); 
        String setTempKeywordsTable= new String ("set table "+ "tempKeywordsTable"+ " source 'E:/Thesis/ThesisWork/outdata/keywords.txt';ignore_first=false;shutdown=true");
        stmt1.execute( setTempKeywordsTable);
        String insertkey=  new String("INSERT INTO keywordsTable"+ "(keywords)"+ "select key from tempKeywordsTable");
        stmt1.executeUpdate(insertkey);
        String dropTempKey= new String("drop table tempKeywordsTable");
        stmt1.executeUpdate(dropTempKey);

但是当我运行这个时,我得到了这个例外:

java.sql.SQLException: bad TEXT table source file - line number: 0 org.hsqldb.HsqlException: Access is denied: E:/Thesis/ThesisWork/outdata/keywords.txt in statement [set table tempKeywordsTable source 'E:/Thesis/ThesisWork/outdata/keywords.txt']
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:73)
Exception in thread "main" java.lang.NullPointerException
at ThesisCode.ReductionTry.main(ReductionTry.java:147)

我搜索了很多以找出问题,但我找不到任何东西。 请给我一些建议。

2 个答案:

答案 0 :(得分:1)

在连接字符串时注意空格,你应该写:

String setTempKeywordsTable= new String ("set table "+"tempKeywordsTable"+ " source 'E:/Thesis/ThesisWork/outdata/keywords.

而不是:

String setTempKeywordsTable= new String ("set table"+ "tempKeywordsTable"+ " source 'E:/Thesis/ThesisWork/outdata/keywords.

你在字符串insertkey中犯了同样的错误。

答案 1 :(得分:0)

我的一个更新:

现在我们必须使用相对路径。例如:db存在于此处:"c:\folder1\folder2"。带有数据的文件应该在folder2或子文件夹中。