【发布时间】:2017-09-17 08:08:45
【问题描述】:
我正在尝试使用 JAVA 在 Vertica 中创建表模型 (i, y1, y2 .... yd)。第 i 列是整数,所有其他都是 REAL。我使用以下代码来创建它。但是,它在 null 处或附近显示语法错误。有人知道那是什么意思吗?该连接适用于该程序。
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];
【问题讨论】:
-
你能分享一下这个方法产生的 SQL 以及你尝试运行它时遇到的确切错误吗?
-
执行创建模型查询时出错 java.sql.SQLSyntaxErrorException: [Vertica][VJDBC](4856) 错误:在“null”或附近出现语法错误BUILD SUCCESSFUL(总时间:1 秒)跨度>
-
您的
Y[x]中至少有一个是null。 -
您展示了如何将数组
Y初始化为 100nulls。在那之后你有没有在其中输入任何String值?您的循环查看Y[1], Y[2], ..., Y[d];你把你的字符串放在Y[0], Y[1],...,Y[d-1]吗? -
是的,@KevinAnderson,我认为你是对的。如何初始化字符串数组的值?
标签: java sql create-table vertica