Click here to Skip to main content
15,881,516 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Where is the condition. In table_a, if col_a and col_b = col_p then col_a + col_b and the result is adding to col_q in table_b and col_p in table_a to col_p table_b.

Java
try{
String sql0 ="SELECT col_p FROM table_a";
PreparedStatement pst0 = conn.prepareStatement(sql0);
   ResultSet rs0 = pst0.executeQuery();
   int colP = rs0.getInt(1);

String sql1 ="SELECT col_a FROM table_a WHERE col_a=" + colP;
String sql2 ="SELECT col_b FROM table_a WHERE col_b=" + colP;
PreparedStatement pst1 = conn.prepareStatement(sql1);
   ResultSet rs1 = pst1.executeQuery();
   int colA = rs1.getInt(1);
PreparedStatement pst2 = conn.prepareStatement(sql2);
   ResultSet rs2 = pst2.executeQuery();
   int colB = rs2.getInt(1);

String sql3 ="INSERT INTO col_q FROM table_b";
PreparedStatement pst3 = conn.prepareStatement(sql3);
   int colQ = colA + colB;
   pst3.setInt(1, colP);
   pst3.setInt(2, colQ);
   pst3.executeUpdate();
}catch (Exception e){
   System.out.println(e);
}


What I have tried:

data entered only 1
Posted
Updated 13-Sep-22 3:36am
v2
Comments
Richard MacCutchan 13-Sep-22 4:41am    
You most likely need a loop to process all records.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900