java - updating in db from resultset -
the sql statement layers returns more 1 value, want update column in db these values problem here?
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+"' membership_num='"+cust_code+"' "; string first_layer="update customers set layers_p = layers_p+'"+layers_p+"' membership_num='"+parent_cod+"'"; int pers_points = st.executeupdate(personal_po); int first_lyr = st.executeupdate(first_layer); string layers="select membership_num customers parent_num='"+parent_cod+"'" ; // want update values comes 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+"' membership_num='"+names+"' "; int nms = st.executeupdate(update_layers);
you should change these lines:
string personal_po = "update customers set personal_p =personal_p + '"+personal_p+"' membership_num='"+cust_code+"' "; string first_layer="update customers set layers_p = layers_p+'"+layers_p+"' membership_num='"+parent_cod+"'"; string update_layers = "update customers set layers_p = layers_p + '"+layers_p+"' membership_num='"+names+"' ";
replacing:
...set xxxxx_p = xxxxx_p + '" + xxxxx_p + "'...
with
...set xxxxx_p = '" + xxxxx_p + "'...
.
update:
also, don't use same statement
updates, while still reading resultset
.
... statement st2 = con.createstatement(); while(rs.next()){ ... int nms = st2.executeupdate(update_layers); } ...
Comments
Post a Comment