gpt4 book ai didi

java - SQL 创建表查询中的 For 循环

转载 作者:行者123 更新时间:2023-12-02 12:14:53 24 4
gpt4 key购买 nike

我正在尝试使用JAVA在Vertica中创建一个表模型(i,y1,y2 .... yd)。第 i 列是整数,其他所有列都是实数。我使用以下代码来创建它。但是,它显示语法错误为空或接近空。有人知道这意味着什么吗?该连接适用于该程序。

 public void createMODEL(int d)
{
int x;
try
{

Statement stmt = conn.createStatement();
String createquery = "CREATE TABLE MODEL ( "
+ "i integer primary key ";
for (x=1;x<=d;x++) createquery+= " , " + Y[x] + " REAL ";
createquery += ")";
stmt.executeUpdate(createquery);
}
catch (Exception e)
{
System.out.println("Error while executing create model query");
System.out.print(e);
System.exit(0);

}

}

Y 定义如下 -

String Y[]=new String[100];

最佳答案

我想你应该检查Y[x]是否不为空:

Statement stmt = conn.createStatement();
String createquery = "CREATE TABLE MODEL ( "
+ "i integer primary key ";
for (x=1;x<=d;x++) {
if (Y[x] != null) createquery+= " , " + Y[x] + " REAL ";
}
createquery += ")";
stmt.executeUpdate(createquery);

关于java - SQL 创建表查询中的 For 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46261975/

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