Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple way to run sqlplus script from java

I've got sql file that contains sqlplus specific script: it includes / or ; as statement terminators, EXEC to execute stored procedures, etc.

I need to execute this script from java (jdbc) without the need for sqlplus.

sql ant task / maven sql plugin can't handle the different terminators or EXEC commands.

Do you know any good way to do so without running sqlplus ?

like image 585
m_vitaly Avatar asked Oct 10 '22 08:10

m_vitaly


1 Answers

We've bumped into the same problem... In brief, there are no ready solutions for that: if you open Ant or Maven sources, you'll see they are using a simple regexp-based script splitter which is fine for simple scripts, but usually fails on e.g. stored procedures.

There are indeed ANTLR parsers for PL/SQL, such as Alexandre Porcelli's one—those are very close, but still not ready to be used as a drop-in solution.

We ended up writing yet another ad hoc splitter which is aware of some sqlplus commands like / and EXIT— it's still ugly, but works for most of our scripts.

like image 92
alf Avatar answered Oct 15 '22 17:10

alf