如何使用Perl CGI脚本中的数据库服务器?

时间:2022-01-31 20:46:38

My program works already, I have Perl (GUI Window) where I can input data, data passed to the webpage (using to Tomcat server, JSP) and then saved it to oracle database. What I want is to make search parameter (webapp) that retrieve/extract data from the Oracle database using Perl CGI. Is it possible? Or any suggestions to solve my program? Thanks!:-)

我的程序已经运行,我有Perl(GUI窗口),我可以在其中输入数据,传递到网页的数据(使用到Tomcat服务器,JSP),然后将其保存到oracle数据库。我想要的是使用Perl CGI创建从Oracle数据库中检索/提取数据的搜索参数(webapp)。可能吗?或者任何解决我的计划的建议?谢谢!:-)

2 个解决方案

#1


5  

Yes you can by using DBI and DBD::Oracle modules.

是的,您可以使用DBI和DBD :: Oracle模块。

However there are some gotchas with Oracle. I remember a few fun and games with Oracle 8 so these may no longer be applicable but it did require setting ENV variables like ORACLE_HOME, ORACLE_BASE & ORACLE_SID in some cases.

然而,Oracle存在一些问题。我记得Oracle 8的一些有趣和游戏因此可能不再适用,但它确实需要在某些情况下设置OR变量,如ORACLE_HOME,ORACLE_BASE和ORACLE_SID。

The DBD::Oracle doc does go into this and also mentions another ENV variable TWO_TASK. So getting it to work may depend on....

DBD :: Oracle doc确实进入了这个,并且还提到了另一个ENV变量TWO_TASK。让它工作可能取决于....

  • what version of Oracle you have running
  • 您运行的是哪个版本的Oracle

  • whether you have listener up (which I think u do need for network access like CGI?)
  • 你是否有听众(我认为你需要像CGI这样的网络访问?)

  • what version SQL*Net your using.
  • 您使用的是什么版本的SQL * Net。

Seems daunting but all you will probably need is to add these ENV variables in the webserver (iPlanet was what I was using at that time). Alternatively from the DBD::Oracle doc it gives...

似乎令人生畏,但你可能需要的只是在网络服务器中添加这些ENV变量(iPlanet就是我当时使用的)。或者从DBD :: Oracle doc中提供......

BEGIN {
  $ENV{ORACLE_HOME} = '/home/oracle/product/10.x.x';
  $ENV{TWO_TASK}    = 'DB';
}
$dbh = DBI->connect('dbi:Oracle:','scott', 'tiger');
#  - or -
$dbh = DBI->connect('dbi:Oracle:','scott/tiger');

PS. The above assumes you are running CGI script on same server as Oracle! If not, then those ENV variables are superfluous and you can just do this (pulled from an old script of mine!)...

PS。以上假设您在与Oracle相同的服务器上运行CGI脚本!如果没有,那么那些ENV变量是多余的,你可以这样做(从我的旧脚本中拉出来!)......

my $db = DBI->connect("dbi:Oracle:host=$host;sid=$database", $user, $pass, 
  { RaiseError => 0, PrintError => 0 } )
  or croak( "Unable to connect to DB - $DBI::errstr" );

However I do recall having to tweak something like TNLISTENER.CONF on the Oracle server (this was some years ago so memory fails me a bit!) and I'm pretty sure you need to download some client Oracle library (which you can get from their site).

但是我确实记得要在Oracle服务器上调整类似TNLISTENER.CONF的东西(这是几年前因为内存让我失望了!)我很确定你需要下载一些客户端Oracle库(你可以从中获取)他们的网站)。

#2


2  

Any specific reason for the mix in technologies? Why not use a servlet/JSP?

混合技术的具体原因是什么?为什么不使用servlet / JSP?

If you must use Perl, then you need to choose what web-server will run your Perl script.

如果必须使用Perl,则需要选择运行Perl脚本的Web服务器。

Normally, this would be Apache using mod_perl.

通常,这将是使用mod_perl的Apache。

But if you only intend to use this for a few admin scripts, then you can run Perl from tomcat as outlined here.

但是如果您只打算将它用于一些管理脚本,那么您可以从tomcat运行Perl,如此处所述。

Once you have managed to get a simple perl script running, then I would look into using DBI/DBD::Oracle to access your database?

一旦你设法运行一个简单的perl脚本,那么我会考虑使用DBI / DBD :: Oracle来访问你的数据库?

Hope this helps...

希望这可以帮助...

#1


5  

Yes you can by using DBI and DBD::Oracle modules.

是的,您可以使用DBI和DBD :: Oracle模块。

However there are some gotchas with Oracle. I remember a few fun and games with Oracle 8 so these may no longer be applicable but it did require setting ENV variables like ORACLE_HOME, ORACLE_BASE & ORACLE_SID in some cases.

然而,Oracle存在一些问题。我记得Oracle 8的一些有趣和游戏因此可能不再适用,但它确实需要在某些情况下设置OR变量,如ORACLE_HOME,ORACLE_BASE和ORACLE_SID。

The DBD::Oracle doc does go into this and also mentions another ENV variable TWO_TASK. So getting it to work may depend on....

DBD :: Oracle doc确实进入了这个,并且还提到了另一个ENV变量TWO_TASK。让它工作可能取决于....

  • what version of Oracle you have running
  • 您运行的是哪个版本的Oracle

  • whether you have listener up (which I think u do need for network access like CGI?)
  • 你是否有听众(我认为你需要像CGI这样的网络访问?)

  • what version SQL*Net your using.
  • 您使用的是什么版本的SQL * Net。

Seems daunting but all you will probably need is to add these ENV variables in the webserver (iPlanet was what I was using at that time). Alternatively from the DBD::Oracle doc it gives...

似乎令人生畏,但你可能需要的只是在网络服务器中添加这些ENV变量(iPlanet就是我当时使用的)。或者从DBD :: Oracle doc中提供......

BEGIN {
  $ENV{ORACLE_HOME} = '/home/oracle/product/10.x.x';
  $ENV{TWO_TASK}    = 'DB';
}
$dbh = DBI->connect('dbi:Oracle:','scott', 'tiger');
#  - or -
$dbh = DBI->connect('dbi:Oracle:','scott/tiger');

PS. The above assumes you are running CGI script on same server as Oracle! If not, then those ENV variables are superfluous and you can just do this (pulled from an old script of mine!)...

PS。以上假设您在与Oracle相同的服务器上运行CGI脚本!如果没有,那么那些ENV变量是多余的,你可以这样做(从我的旧脚本中拉出来!)......

my $db = DBI->connect("dbi:Oracle:host=$host;sid=$database", $user, $pass, 
  { RaiseError => 0, PrintError => 0 } )
  or croak( "Unable to connect to DB - $DBI::errstr" );

However I do recall having to tweak something like TNLISTENER.CONF on the Oracle server (this was some years ago so memory fails me a bit!) and I'm pretty sure you need to download some client Oracle library (which you can get from their site).

但是我确实记得要在Oracle服务器上调整类似TNLISTENER.CONF的东西(这是几年前因为内存让我失望了!)我很确定你需要下载一些客户端Oracle库(你可以从中获取)他们的网站)。

#2


2  

Any specific reason for the mix in technologies? Why not use a servlet/JSP?

混合技术的具体原因是什么?为什么不使用servlet / JSP?

If you must use Perl, then you need to choose what web-server will run your Perl script.

如果必须使用Perl,则需要选择运行Perl脚本的Web服务器。

Normally, this would be Apache using mod_perl.

通常,这将是使用mod_perl的Apache。

But if you only intend to use this for a few admin scripts, then you can run Perl from tomcat as outlined here.

但是如果您只打算将它用于一些管理脚本,那么您可以从tomcat运行Perl,如此处所述。

Once you have managed to get a simple perl script running, then I would look into using DBI/DBD::Oracle to access your database?

一旦你设法运行一个简单的perl脚本,那么我会考虑使用DBI / DBD :: Oracle来访问你的数据库?

Hope this helps...

希望这可以帮助...