I am trying to create a text table set its values from a file and then insert these values back into a normal table using hsqldb in a Java code as shown in this code:
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);
But when I run this I got this exception:
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)
I searched a lot to figure out the problem but I could not find anything. Please give me some advice.
Watch out for the spaces when concatenating strings, you should write:
String setTempKeywordsTable= new String ("set table "+"tempKeywordsTable"+ " source 'E:/Thesis/ThesisWork/outdata/keywords.
instead of:
String setTempKeywordsTable= new String ("set table"+ "tempKeywordsTable"+ " source 'E:/Thesis/ThesisWork/outdata/keywords.
You're doing the same mistake in String insertkey
.