【发布时间】:2016-01-09 14:46:57
【问题描述】:
我已经使用 JDBC 连接到 SQL Server。我运行的查询之一具有数据类型位,当我运行程序时出现此错误:SQLException: Incorrect syntax near 'bit'。
这是我的代码:
String sql3 = "SELECT DISTINCT customCategoryDescription FROM product_categories ORDER BY customCategoryDescription";
rs2 = stmt3.executeQuery(sql3);
while (rs2.next())
{
String customCategoryDescription = rs2.getString("customCategoryDescription");
columns.add(customCategoryDescription);
}
rs2.close();
stmt3.close();
for(int i = 0; i < columns.size(); i++)
{
String sql4 = "ALTER TABLE transformed_table ADD "+columns.get(i)+" bit";
stmt4.executeUpdate(sql4);
stmt4.close();
}
我在 SQL Server 中尝试了相同的查询,并成功添加了列。
问题出在哪里?
【问题讨论】:
-
您应该编辑您的问题并在变量替换后打印出
sql4。 -
@GordonLinoff ALTER TABLE encrypted_table ADD B2B 解决方案位 也许问题是因为空格字符。但是我怎样才能删除它呢?
-
如果列名中有空格,请将列放在方括号之间。
标签: java sql-server jdbc