0

我无法根据我的代码生成视图,如下所示:

final String[] clusterClasses = {"exponential", "linear", "periodic"};
java.sql.PreparedStatement pCreateViewStmt = conn.prepareStatement(
    "create view ?_? as "
    + "select * from golden_table where clust_list like ? ?");

for(int i = 0; i < clusterClasses.length; i++) {
    for(int j = 0; j < clusterClasses.length; j++) {
        pCreateViewStmt.setString(1, clusterClasses[i]);
        pCreateViewStmt.setString(2, clusterClasses[j]);
        pCreateViewStmt.setString(3, "%"+clusterClasses[i]);
        pCreateViewStmt.setString(4, "%"+clusterClasses[j]+"%");
    }
}

我得到一个 SQL 语法异常:

Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 
You have an error in your SQL syntax; check the manual that corresponds to your 
MySQL server version for the right syntax to use near ''exponential'_'periodic' 
as select * from golden_table where clust_list like '%e' at line 1

这与 PreparedStatement 和通配符有关,但?我不太明白。

以下是循环的一次迭代i可以作为创建视图命令产生的内容:

create view exponential_periodic AS 
select * 
  from golden_table
  where clust_list like '%exponential%periodic%';
4

0 回答 0