This is my SQL code, a simple transaction. When I run it on MariaDB using run as script it works well, but it doesn't work with run as SQL Statement.
START TRANSACTION;
SELECT * from employee;
insert into Employee (id,name) values (:id,:name)
COMMIT;
I want to use this sql code directly in my Java code:
I am using jdbc url as "jdbc:mariadb://localhost:3306/test_mariadb?user=root&password=<password>";
String sql = "START TRANSACTION;
SELECT * from employee;
insert into Employee (id,name) values (:id,:name)
COMMIT;"
Connection connection = connect();
Statement stmt = connection.createStatement();
ResultSet resultSet = stmt.executeQuery(sql);
I am getting below error:
Caused by: java.sql.SQLException: 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 * from employee;insert into Employee (id,name) values (150,'150_abc');...' at line 1