0

I am fresher and I have to write below code

I Have 2 list's called accounts and accountTotalAmount, I want to iterate through these lists at the same time

   Class FormDetails
    {
        private List<String> accounts;
        private List<String> accountTotalAmount;

         //getter & setter;
        //toString();
      }



       final CallableStatement call = connection.prepareCall("{ ? = call "+Schema+"table_name(?) }");
      for(final String account : formData.getAccounts())
         {
                
                call.setString(1, account);
                call.execute();
         }

I have to get and set accounttotalamount into 2 column for callableStatement using same advance for loop

Thanks in advance !!

  • 3
    Does this answer help: https://stackoverflow.com/a/1365810/9698467 – Stefan Zhelyazkov Mar 04 '21 at 09:50
  • Let's see if I understand your question. You have data in both `accounts` and `accountTotalAmount` and you want to update the database with that data by calling a database stored function named `table_name` which takes a single parameter. Is that correct? – Abra Mar 04 '21 at 11:26
  • Yes,Abra.I am able to update the database using single parameter(accounts) .Now I have to update database with second parameter (accountTotalAmount) using same above stored function.Is it Possible? – Vikram1209 Mar 04 '21 at 11:59
  • It's still not clear (to me, at least). You need to update the database with **both** `accounts` **and** `accountTotalAmount`? What is the database data type of the parameter in the stored function `table_name`? Is it a built-in type, like `VARCHAR`? And what DBMS are you using? Stored routines are not standard SQL. Each DBMS has its own language for writing stored routines. – Abra Mar 04 '21 at 13:27
  • Yes, I need to update the database with both accounts and accountTotalAmount. Table name is Account_CTA and datatype is NUMBER. I am using oracle database and i have to get totalamounts and set it for 2nd row like below code used for 1st row for(final String :formData.getAccounts()) { call.setString(1, account); call.execute(); } – Vikram1209 Mar 04 '21 at 18:39
  • You can [edit] your question. Don't put question details in comments. Which columns do you want to update in database table `Account_CTA`? Which column is updated with `account` and which column is updated with `accountTotalAmount`? Maybe even post the code of the stored function (if possible) so that I can understand what it does. – Abra Mar 05 '21 at 05:43

1 Answers1

0

Create a new object which encapsulates both accounts and accountTotalAmount. Throw it into a new array, such as:

List<SomethingSomething>

Where you initiliase what you need:

public class SomethingSomething() {
   public String amount;
   public String accountTotalAmount;
}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
stafino
  • 37
  • 10