I want to merge four different SQL queries into single query in order to reduce usage of SQL connections
This is my code:
long WTPty = 0L; // holds some value from other part of program
long NTPty = 0L; // holds some value from other part of program
long ETPty = 0L; // holds some value from other part of program
long STPty = 0L; // holds some value from other part of program
Statement stmt = (Statement) conn.createStatement();
//query 1
String w_tblpty="update tbl_priority SET total='"+WTPty+"' where priority= 'west'";
stmt.executeUpdate(w_tblpty);
//query 2
String n_tblpty="update tbl_priority SET total='"+NTPty+"' where priority= 'north'";
stmt.executeUpdate(n_tblpty);
//query 3
String s_tblpty="update tbl_priority SET total='"+STPty+"' where priority= 'south'";
stmt.executeUpdate(s_tblpty);
//query 4
String e_tblpty="update tbl_priority SET total='"+ETPty+"' where priority= 'east'";
stmt.executeUpdate(e_tblpty);
My objective is to reduce SQL connection usage and optimize the code. Is it possible to merge the above four queries into just single one?
addBatch...UPDATEstatements are not queries. A "query" is defined in the English language as "a question or a request for information". In SQL context, that means aSELECTstatement.