简体   繁体   中英

Oracle script run from Java code without installing Oracle client

I write application that work on Oracle database and I have to have possibility to run sql script from java code on database. Now I do it with help of sqlplus.exe app, but this solution forces me to have Oracle client installed so I want to know if there is any way to run sql scripts from java code but without sqlplus.exe. I found articles which describes solution based on ant task but as I know it would force me to attach ant buid infrastructure to application. Best solution for me would be get special jar use some magic class from that jar and have it done with that class :) Is it possible ?

Oracle basically uses three languages:

  • SQL (commands like SELECT, INSERT, CREATE TABLE etc.)
  • PL/SQL (the procedural language including variable declarations, loops, exceptions)
  • SQLplus commands (SET DEF, VARIABLE, @, slash (/) to execute blocks of PL/SQL etc.)

With the Java client (ojdbc.jar) you can execute single SQL statements and PL/SQL blocks at a time. But it has no support for SQLplus whatsoever.

If your scripts are simple, then you can write a parser that splits the scripts into single SQL statements and blocks of PL/SQL and execute them one by one. But if you use SQLplus commands, then it won't be possible.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM