'How to run multiple queries in single statement [duplicate]

This is my SQL code, a simple transaction. When i run it on phpmyadmin it's work well.

START TRANSACTION;
SELECT received_money FROM bank_accounts WHERE `uuid` = "2eaef3e4-eeb6-41f7-9ecf-5d503465baba";
UPDATE bank_accounts SET received_money = 0 WHERE `uuid` = "2eaef3e4-eeb6-41f7-9ecf-5d503465baba";
COMMIT;

But i want to use this sql code directly in my Java code:

String sql = "START TRANSACTION;\n" +
            "SELECT placed_money FROM bank_accounts WHERE uuid = \"" + uuid + "\";\n" +
            "UPDATE bank_accounts SET placed_money = 0 WHERE uuid = \"" + uuid + "\";\n" +
            "COMMIT;";
Connection connection = connect();
Statement stmt = connection.createStatement();
ResultSet resultSet = stmt.executeQuery(sql);

But every time i have this error

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'SELECT received_money FROM bank_accounts WHERE `uuid` = "2eaef3e4-eeb6-41f7-9ecf' at line 2


Solution 1:[1]

That is a multiple queries.

so you need a connection string that allows that

String dbUrl = "jdbc:mysql:///test?allowMultiQueries=true"; 

Further remove all \ n and as i said in the comment replace "

String sql = "START TRANSACTION;" +
        "SELECT placed_money FROM bank_accounts WHERE uuid = '" + uuid + "';" +
        "UPDATE bank_accounts SET placed_money = 0 WHERE uuid = '" + uuid + "';" +
        "COMMIT;"; 

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 nbk