是否正在按照我尝试的方式更新多个表格? 如果是这样,任何人都可以看到我的代码出了什么问题,我的命令没有正确结束语法错误
public void updateProdCD(DigiProduct p)
{
try {
String queryString = "UPDATE Product SET p.prod_id=?,"
+" p.prod_type=?, "
+" c.album_name=?, "
+" c.cd_cost_price=?, "
+" c.cd_sale_price=?, "
+" p.current_stock=?, "
+" dp.age_rating=?, "
+" dp.genre=?, "
+" c.record_company=?, "
+" c.album_length=? "
+" FROM product p, digital_product dp, "
+" cd c, artist a, cd_artist ca "
+"WHERE dp.prod_id = p.prod_id "
+"AND dp.dig_id = c.dig_id "
+"AND a.artist_id = ca.artist_id "
+"AND c.cd_id = ca.cd_id "
+"AND prod_id ="+ "'" + p.getProd_id() + "'";
pstmt = conn.prepareStatement(queryString);
pstmt.setString(1, p.getProd_id() );
pstmt.setString(2, p.getProd_type());
pstmt.setString(3, p.getAlbumName());
pstmt.setDouble(4, p.getCostPrice());
pstmt.setDouble(5, p.getSellPrice());
pstmt.setInt(6, p.getCurrent_stock());
pstmt.setString(7, p.getAge_rating() );
pstmt.setString(8, p.getGenre());
pstmt.setString(9, p.getPublisher());
pstmt.setDouble(10, p.getLength());
pstmt.executeUpdate();
updateAlbum(p);
}catch (Exception ex)
{
System.out.println(ex);
}
}
答案 0 :(得分:3)
UPDATE some_table SET [fields_list] FROM [tables] WHERE [predicates]
是不正确的SQL语法。除非是存储过程调用,否则无法在一个查询中更新多个表的字段。
尝试
UPDATE table_name SET [fields_list] WHERE [predicates]
。