Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you put multiple statements in one query-string in Oracle jdbc?

I have a JDBC connection to an Oracle database. I create a Statement. The SQL query String contains multiple statements separated by a semicolon, and is provided by a different system.

Example:

connection.prepareStatement("SELECT * FROM A; SELECT * FROM B");

According to ddimitrov it isn't possible.

But all other databases I've tried support it. And JDBC even has support to retrieve multiple results.

Does anyone have either pointers to Oracle documentation explicitly stating that it is not supported or have a way to make it work (without using of stored procedures)?

like image 729
Roel Spilker Avatar asked Oct 23 '25 04:10

Roel Spilker


2 Answers

For executing multiple statements:

JDBC 2.0 lets you submit multiple statements at one time with the addBatch method

See here.

like image 145
Óscar López Avatar answered Oct 25 '25 16:10

Óscar López


No, this is not possible with the Oracle JDBC driver.

You will have to parse and split the string into their individual statements.

Btw: I think the only databases that allow this are Microsoft SQL Server and MySQL. Which also makes them vulnerable to certain kind of SQL injection attacks that would not work Oracle or PostgreSQL.