简体   繁体   English

从Java代码运行Oracle脚本而无需安装Oracle客户端

[英]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. 我编写在Oracle数据库上工作的应用程序,并且必须有可能从数据库上的Java代码运行sql脚本。 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. 现在,我在sqlplus.exe应用程序的帮助下进行了此操作,但是此解决方案迫使我安装了Oracle客户端,因此我想知道是否有任何方法可以从Java代码运行sql脚本,但没有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. 我找到了描述基于ant任务的解决方案的文章,但据我所知,这将迫使我将ant buid基础结构附加到应用程序。 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 ? 对我来说最好的解决方案是使用该jar中的一些魔术类来获得特殊的jar,并使用该类完成它:)有可能吗?

Oracle basically uses three languages: Oracle基本上使用三种语言:

  • SQL (commands like SELECT, INSERT, CREATE TABLE etc.) SQL(诸如SELECT,INSERT,CREATE TABLE等命令)
  • PL/SQL (the procedural language including variable declarations, loops, exceptions) PL / SQL(包括变量声明,循环,异常的过程语言)
  • SQLplus commands (SET DEF, VARIABLE, @, slash (/) to execute blocks of PL/SQL etc.) SQLplus命令(SET DEF,VARIABLE,@,斜杠(/)执行PL / SQL块等)

With the Java client (ojdbc.jar) you can execute single SQL statements and PL/SQL blocks at a time. 使用Java客户端(ojdbc.jar),您可以一次执行单个SQL语句和PL / SQL块。 But it has no support for SQLplus whatsoever. 但是它不支持SQLplus。

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. 如果您的脚本很简单,那么您可以编写一个解析器,将脚本分成单个SQL语句和PL / SQL块,然后逐个执行它们。 But if you use SQLplus commands, then it won't be possible. 但是,如果使用SQLplus命令,则将不可能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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