Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
151 views
in Technique[技术] by (71.8m points)

java - Is it possible to put two ResultSet in one method and run it?

hello i wanted to ask a question. Is it possible to put two ResultSet in one method and run it?

Basically this is which banking system and i need to run two ResultSet at the same time.

               System.out.println(resultSet.getString(1));
               double amount2 = resultSet.getDouble(1);
               if (amount <= amount2) {
                   Statement s = connection.createStatement();

                   String query3 = "SELECT balance FROM Accounts WHERE id = '" + toAccount + "'";


                   ResultSet resultSet1 = preparedStatement.executeQuery(query3);

                   double amount4 = resultSet1.getDouble(1);

                   System.out.println("To user: " + amount4);
                   double amount5 = amount4 + amount;
                   String s2 = "UPDATE Accounts SET balance  = '" + amount5 + "' WHERE id = '" + toAccount + "'";

                   double amount3 = amount2 - amount;

                   System.out.println("User balance: " + amount3);

                   String s1 = "UPDATE Accounts SET balance  = '" + amount3 + "' WHERE id = '" + fromAccount + "'";
                   s.addBatch(s1);
                   s.addBatch(s2);
                   s.executeBatch();

                   Transactions transactions = new Transactions(fromAccount, toAccount, amount);
                   newTransaction(transactions);

question from:https://stackoverflow.com/questions/66048837/is-it-possible-to-put-two-resultset-in-one-method-and-run-it

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...