我尝试这样做可以更新多个表吗?
如果有人可以看到我的代码出了什么问题,那我得到的命令是未正确结束的语法错误

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);
        }
    }

最佳答案

UPDATE some_table SET [fields_list] FROM [tables] WHERE [predicates]是错误的SQL语法。除非是存储过程调用,否则不可能在一个查询中更新多个表的字段。

尝试

UPDATE table_name SET [fields_list] WHERE [predicates]

尝试看一下这个问题:How to update multiple tables at the same time?

关于java - 更新多个表JDBC,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23153521/

10-10 13:54