我已使用JDBC連接到SQL Server。我運行的查詢之一有數據類型位,當我運行該程序時,出現此錯誤:SQLException:'位'附近的語法錯誤。SQLException:「位」附近的語法不正確
這裏是我的代碼:
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 transformed_table ADD B2B Solutions位 也許問題是由於空間的特點。但是我怎樣才能刪除它? –
如果列名稱中有空格,請將該列放在矩形括號之間。 –