我在txt文件中有一个矩阵保存,我想将它加载到hsqldb表中,矩阵中的每一列都加载到表中的一列中。
这就是我做的事情
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);
tableName的结构如下 ID | a1 | a2 | a3 ....等等
tempMatrixTable的结构如下 a1 | a2 | a3 ....等等
当我运行此代码时,我遇到了这个异常
java.sql.SQLSyntaxErrorException: unexpected token: ( --> It refers to the line to execute the set statement
请指导我
由于
答案 0 :(得分:1)
表格名称后面不应该有一个左括号:
String setTempMatrixTable= new String ("set table "+"tempMatrixTable"+ " source 'matrix.txt'");