我需要通过从另一个表A中获取详细信息来更新表B中的记录集。如何使用for
循环来使用java实现此目的?
注意 - 我从Config属性中获取SQL查询
//---------- ------------------Get all the required Online data -------
ArrayList<String> OnlineData_0 = new ArrayList<String>();
ArrayList<String> OnlineData_1 = new ArrayList<String>();
ArrayList<String> OnlineData_2 = new ArrayList<String>();
ArrayList<String> OnlineData_3 = new ArrayList<String>();
String GetOnlineDataQuery = prop.getProperty("GetOnlineDataQuery_Auth");
OnlineRecords = DataBaseConnector.executeSQLQuery_List2("QA", GetOnlineDataQuery);
then i need to get the column details of reach record
//----------------------------Get each online record column details--------
String GetRecordDetail_0 = prop.getProperty("GetRecordDetail") + onlineRecords.get(0);
String GetRecordDetail_1 = prop.getProperty("GetRecordDetail") + OnlineRecords.get(1);
String GetRecordDetail_2 = prop.getProperty("GetRecordDetail") + OnlineRecords.get(2);
String GetRecordDetail_3 = prop.getProperty("GetRecordDetail") + OnlineRecords.get(3);
String GetRecordDetail_4 = prop.getProperty("GetRecordDetail") + OnlineRecords.get(4);
Now i need to uddate the above column details to records in different table
//-----------------update the column details in Table B---------------------------------------------
String Query_UpdateClearingRecord_Auth_0 = prop.getProperty("Query_UpdateClearingRecord_Auth") + OnlineRecords.get(0);
String Query_UpdateClearingRecord_Auth_1 = prop.getProperty("Query_UpdateClearingRecord_Auth") + OnlineRecords.get(1);
String Query_UpdateClearingRecord_Auth_2 = prop.getProperty("Query_UpdateClearingRecord_Auth") + OnlineRecords.get(2);
String Query_UpdateClearingRecord_Auth_3 = prop.getProperty("Query_UpdateClearingRecord_Auth") + OnlineRecords.get(3);
String Query_UpdateClearingRecord_Auth_4 = prop.getProperty("Query_UpdateClearingRecord_Auth") + OnlineRecords.get(4);
String update_ISO8583_Query_0 = DataBaseConnector.executeSQLQuery("QA", Query_UpdateClearingRecord_Auth_0);
String update_ISO8583_Query_1 = DataBaseConnector.executeSQLQuery("QA", Query_UpdateClearingRecord_Auth_1);
String update_ISO8583_Query_2 = DataBaseConnector.executeSQLQuery("QA", Query_UpdateClearingRecord_Auth_2);
String update_ISO8583_Query_3 = DataBaseConnector.executeSQLQuery("QA", Query_UpdateClearingRecord_Auth_3);
String update_ISO8583_Query_4 = DataBaseConnector.executeSQLQuery("QA", Query_UpdateClearingRecord_Auth_4);
如何将上述内容置于for循环中以便我可以更新记录
答案 0 :(得分:0)
我建议不要在for循环中进行sql查询。这会给您的数据库带来很大的负担,并可能导致数据库崩溃。您应该查看数据库的批量操作。
for(int i=0; i<onlineRecords.size(); i++ ){
String GetRecordDetail_i = prop.getProperty("GetRecordDetail") + onlineRecords.get(i);
String Query_UpdateClearingRecord_Auth_i = prop.getProperty("Query_UpdateClearingRecord_Auth") + OnlineRecords.get(i);
String update_ISO8583_Query_i = DataBaseConnector.executeSQLQuery("QA", Query_UpdateClearingRecord_Auth_i);
}