将数据从文本表传输到普通表hsqldb java

时间:2022-05-21 23:37:30

I am trying to transfer data from a text table to a normal table, where the data is taken originally from a txt file.

我正在尝试将数据从文本表传输到普通表,其中数据最初来自txt文件。

I am using hsqldb

我正在使用hsqldb

This is what I did. I have no error or exception , but both the tables are empty.

这就是我所做的。我没有错误或异常,但两个表都是空的。

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))");
        stmt1.executeUpdate(sqlkeywordcreate);
        stmt1.executeUpdate(sqlkeywordcreate1);
        int numOfFields=di.getAllTerms();
String setTempKeywordsTable= new String ("set table "+"tempKeywordsTable"+ " source 'keywords.txt'");
        //System.out.print(setTempKeywordsTable);
        stmt1.executeUpdate( 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);
        String sqlcreate=new String("CREATE TABLE "+ tableName +" (id INTEGER IDENTITY not NULL PRIMARY KEY)");
        String sqlselect=new String("select k_id from keywordsTable");

Please guide me and give me ideas to solve this issue. Thanks

请指导我并给我解决这个问题的想法。谢谢

1 个解决方案

#1


1  

The code looks correct. You should add a test count after the line with "set table tempKeywordsTable source " to make sure the data is linked properly to the TEXT table. If there is data, the rest will work.

代码看起来正确。您应该在“set table tempKeywordsTable source”行后面添加一个测试计数,以确保数据正确链接到TEXT表。如果有数据,其余的都可以使用。

A possible cause of your code not working is the path of the keywords.txt file. This file should be in the same directory as the rest of the database files.

代码无法工作的可能原因是keywords.txt文件的路径。此文件应与其余数据库文件位于同一目录中。

#1


1  

The code looks correct. You should add a test count after the line with "set table tempKeywordsTable source " to make sure the data is linked properly to the TEXT table. If there is data, the rest will work.

代码看起来正确。您应该在“set table tempKeywordsTable source”行后面添加一个测试计数,以确保数据正确链接到TEXT表。如果有数据,其余的都可以使用。

A possible cause of your code not working is the path of the keywords.txt file. This file should be in the same directory as the rest of the database files.

代码无法工作的可能原因是keywords.txt文件的路径。此文件应与其余数据库文件位于同一目录中。