-2

SQL 语句层返回多个值,我想用所有这些值更新 db 中的一列这里有什么问题?

        String cust_code = session.getAttribute("Cust_Code").toString();
        String video_typ = session.getAttribute("video_typ").toString();
        int personal_p = Integer.parseInt(session.getAttribute("personal_p").toString());
        int layers_p = Integer.parseInt(session.getAttribute("layers_p").toString());
        String parent_cod = session.getAttribute("parent_code").toString();
        Class.forName("com.mysql.jdbc.Driver");
        Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/ontube", "root", "123456");
        Statement st = con.createStatement();
        String personal_po = "update customers set personal_p =personal_p + '"+personal_p+"' where membership_num='"+cust_code+"'  ";
        String first_layer="update customers set layers_p = layers_p+'"+layers_p+"' where membership_num='"+parent_cod+"'";
        int pers_points = st.executeUpdate(personal_po);
        int first_lyr = st.executeUpdate(first_layer);
        String layers="select membership_num from customers where parent_num='"+parent_cod+"'" ;
        // i want to update all values comes from these resultset
        ResultSet rs = st.executeQuery(layers);

        while(rs.next()){
       String names =rs.getString(1);

       String update_layers = "update customers set layers_p = layers_p + '"+layers_p+"' where membership_num='"+names+"'  ";

       int  nms = st.executeUpdate(update_layers);
4

2 回答 2

0
String update_layers = "update customers set layers_p = layers_p + '" + layers_p + "' where membership_num='" + names + "'  ";

应该:

String update_layers = "update customers set layers_p = '" + layers_p + "' where membership_num='" + names + "'  ";
于 2013-05-13T07:57:05.683 回答
0

您应该更改这些行:

String personal_po = "update customers set personal_p =personal_p + '"+personal_p+"' where membership_num='"+cust_code+"'  ";
String first_layer="update customers set layers_p = layers_p+'"+layers_p+"' where membership_num='"+parent_cod+"'";
String update_layers = "update customers set layers_p = layers_p + '"+layers_p+"' where membership_num='"+names+"'  ";

替换:
...set xxxxx_p = xxxxx_p + '" + xxxxx_p + "'...
...set xxxxx_p = '" + xxxxx_p + "'....

更新
另外,在阅读时不要使用相同Statement的更新ResultSet

...
Statement st2 = con.createStatement();
while(rs.next()){
    ...
    int  nms = st2.executeUpdate(update_layers);
}
...
于 2013-05-13T08:02:15.037 回答