I'm using java with postresql driver and I want to run multiply queries in one statement (if possible)
I'm aware of running batch queries like this:
pstmt = connection.createStatement();
pstmt.addBatch("query1 here");
pstmt.addBatch("query2 here");
pstmt.executeBatch();
but is there a way to execute multiply queries with parameters?
Something like this:
pstmt = connection.prepareStatement(
"UPDATE TABLE Example SET name=? WHERE id = ?;\n" +
"UPDATE TABLE Other SET name=? WHERE id = ?;"
);
pstmt.setInt(1, "name");
pstmt.setInt(2, id1);
pstmt.setInt(3, "kuku");
pstmt.setInt(4, id2);
pstmt.execute();
--
UPDATE
The link in the comment (this) answers half of my question.
In addition, I want to know if there is a way to run two different queries.
Lets say the queries above were:
UPDATE table1 SET col=? WHERE id=?;
INSERT INTO table2 VALUES (?, ?, ?);
As it seems there is not way to do that... :/ Thanks.