执行 Java 的 Oracle 作业
是否可以从 Oracle (10g) 数据库中运行 java jar 文件?更具体地说,我希望使用
dbms_scheduler.create_job(...)
运行时安排一个 oracle 作业,该作业将调用一个 Java 应用程序,该应用程序执行一个涉及通过 HTTP 与另一个应用程序通信的过程,一些业务逻辑,然后使用 JDBC 对数据库执行存储过程。
通常,执行此操作的 chron 作业可以正常工作,但 java 应用程序需要作为给定架构所有者与数据库进行通信。出于各种隐私原因,我无法将用户凭据以纯文本形式存储在应用程序配置中。
简而言之,我想知道是否有一种方法可以安排作业来执行 jar,并传入安排作业的用户的凭据。
我对调度 Oracle 作业和从 Oracle 数据库运行 Java 代码都不熟悉,因此任何正确方向的指针都会很棒。我还没有真正找到任何像样的文档来说明我正在尝试做的事情,尽管我确信它必须存在。
编辑:找到了一些文档,看起来我可以做类似的事情
DBMS_SCHEDULER.create_program (
program_name => 'recurring_java_task',
program_type => 'EXECUTABLE',
program_action => 'java -jar /path/to/recurring-task.jar',
number_of_arguments => 2,
enabled => TRUE,
comments => 'Program to perform cleanup');
,然后使用 dbms_scheduler.create_job(...)
为“recurring_java_task”创建作业。似乎参数是使用设置的,
DBMS_SCHEDULER.SET_JOB_ARGUMENT_VALUE (
job_name IN VARCHAR2,
argument_position IN PLS_INTEGER,
argument_value IN VARCHAR2);
但这仍然不能解决向 java 应用程序提供连接凭据(用户名/密码)的问题。
Is it possible to run a java jar file from within an Oracle (10g) database? More specifically, I am looking to schedule an oracle job using
dbms_scheduler.create_job(...)
When run, the job would call a Java Application that performs a process involving talking to another application via HTTP, some business logic, then executing a Stored Procedure against the database using JDBC.
Normally, a chron job to do this would work fine, but the java application needs to talk to the database as a given Schema Owner. I can't store the user-credentials as plain text in the application configuration for various privacy reasons.
In short, I'm wondering if there is a way to schedule a job to execute a jar, passing in the credentials of the user who scheduled the job.
I am unfamiliar with both scheduling Oracle Jobs and running Java Code from an Oracle Database so any pointers in the right direction would be great. I haven't really been able to find any decent documentation for what I am trying to do either, although I'm sure it has to exist.
EDIT: found some documentation and it looks like I could do something like
DBMS_SCHEDULER.create_program (
program_name => 'recurring_java_task',
program_type => 'EXECUTABLE',
program_action => 'java -jar /path/to/recurring-task.jar',
number_of_arguments => 2,
enabled => TRUE,
comments => 'Program to perform cleanup');
and then use
dbms_scheduler.create_job(...)
to create a job for the 'recurring_java_task'. It seems like Arguments are set using
DBMS_SCHEDULER.SET_JOB_ARGUMENT_VALUE (
job_name IN VARCHAR2,
argument_position IN PLS_INTEGER,
argument_value IN VARCHAR2);
That still doesn't solve the issue of supplying connection credentials (username/password) to the java application, though.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将 Java 放入数据库中。 Oracle 10.2 Java 开发指南。这使用了一个特殊的 JDBC 连接字符串,该字符串实际上引用了内部会话。有一些特殊的考虑,即没有GUI渲染等。您也可以在pl/sql中调用并包装它。
You can put the Java IN the database. Oracle 10.2 Java Dev Guide. This uses a special JDBC connection string that actually references the internal session. There are special considerations, i.e no GUI rendering, etc. You can also call and wrap this in pl/sql.