2014-06-06 26 views
0

我有一個保存在txt文件中的矩陣,我想將它加載到hsqldb表中,矩陣中的每一列都被加載到表中的一列中。設置文本表hsqldb java異常

這是我做過什麼

kId= new String[numOfFields]; 
     String f=""; 
     String ff=""; 
     String fff=""; 
      for (int i=0;i<kId.length;i++) { 
       while(rss.next()) 
       { 
       kId[i]=rss.getString(1); 
       f="a"+kId[i]+ " varchar(7)"; 
       ff+="a"+kId[i]+", "; 
       fff+="a"+kId[i]+ " varchar(7), "; 
       String sqlalter=new String("ALTER TABLE "+ tableName +" add "+f+""); 
       //System.out.println(sqlalter); 
       stmt1.executeUpdate(sqlalter); 
      } 

     } 
      f=f.substring(0, f.length()-1); 
      ff = ff.replaceAll(", $",""); 
      fff = fff.replaceAll(", $",""); 

     String sqlmatrixcreate=new String ("CREATE TEXT TABLE tempMatrixTable " + " ("+fff+") "); 
     //System.out.print(sqlmatrixcreate); 
     stmt1.executeUpdate(sqlmatrixcreate); 
     String setTempMatrixTable= new String ("set table "+"tempMatrixTable"+ " ("+ff+") " + " source 'matrix.txt'"); 
     stmt1.executeUpdate(setTempMatrixTable); 
     String insertWeight= new String("INSERT INTO "+ tableName +"("+ff+")"+ " select weight from tempMatrixTable"); 
     System.out.print(insertWeight); 
     stmt1.executeUpdate(insertWeight); 
     String dropTempWeight= new String("drop table tempMatrixTable"); 
     //stmt1.executeUpdate(dropTempKey); 

表名的結構如下 ID | a1 | a2 | a3 ....等等

tempMatrixTable的結構如下 a1 | a2 | A3 ....等等

當我運行這段代碼,我得到這個例外

java.sql.SQLSyntaxErrorException: unexpected token: ( --> It refers to the line to execute the set statement 

請指引我

感謝

回答

1

不應該有後開式括號表名:

String setTempMatrixTable= new String ("set table "+"tempMatrixTable"+ " source 'matrix.txt'");