gpt4 book ai didi

java - 设置文本表hsqldb java异常

转载 作者:行者123 更新时间:2023-12-01 12:52:55 24 4
gpt4 key购买 nike

我有一个矩阵保存在 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的结构如下身份证 | a1 | a2 | a3 ....等等

tempMatrixTable的结构如下a1 | a2 | a3 ....等等

当我运行此代码时,出现此异常

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

请指导我

谢谢

最佳答案

表名后面不应有左括号:

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

关于java - 设置文本表hsqldb java异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24088540/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com