Home: Perl Programming Help: DBI:
perl jdbc

New User

Dec 27, 2008, 2:48 PM

Views: 5916
perl jdbc

I am using jdbc to connect perl to oracle using
source("usr/bin/perl ...... ")
for my web mining project.

when I execute it using

>perl file.pl

it enters values in the database but when I try to run my interface on browser it does not do anything.

Veteran / Moderator

Dec 28, 2008, 9:06 AM

Views: 5904
Re: [pappusingh] perl jdbc

When a perl script runs correctly from the command line but not when called as a cgi script, the most common reason is incorrect permission settings.

Have you looked at the web server error log? It should give you some clues.

Can you post the script for us to review?

New User

Dec 29, 2008, 1:23 AM

Views: 5895
Re: [FishMonger] perl jdbc

hi.. I am trying to execute this in perl

so when I click a link on my site it calls the cgi script and collects environment variables. Then I enter some information in the database.

I don't think its because of permissions because I have another script which uses another java file to insert data in database!! and that works.

this part of code calls the java program log.java

system( "/usr/bin/java log '$DAY' '$TIME' '$FROM_URL' '$QUERY' '$REMOTE_IP' '$SERVER_PROTOCOL' '$GATEWAY_INTERFACE'");

which enters the values in the database as follows

String query = "insert into log( REQUEST_ID, DAY, TIME, FROM_URL, TO_URL, REMOTE_IP, SERVER_PROTOCOL, GATEWAY_INTERFACE) values (log_seq.nextval, '"+args[0]+"','"+args[1]+"', '"+args[2]+"', '"+args[3]+"', '"+args[4]+"', '"+args[5]+"','"+args[6]+"')";

REQUEST_ID is the primary key and auto increment.
all other fields are of type varchar. none of them except primary key is NOT NULL.
and to be specific for first couple of times when I call the cgi script some fields for example $FROM_URL will be passing NULL.
Does that creating a problem ?

In Reply To

Veteran / Moderator

Dec 29, 2008, 7:58 AM

Views: 5889
Re: [pappusingh] perl jdbc

Passing NULL values are fine as long as the db field allows it, but are sure that's what you're doing?

Could you be passing undef instead of NULL? They are not the same.
As a debugging test, you could print the string in the system call to verify it what you expect.

print "/usr/bin/java log '$DAY' '$TIME' '$FROM_URL' '$QUERY' '$REMOTE_IP' '$SERVER_PROTOCOL' '$GATEWAY_INTERFACE'";

There are several things you could do to fix this problem. The first and best starting point would be to use Perl's DBI and DBD::Oracle modules to interface with your Oracle db instead of doing the system call to a java program.

The next step would be to make sure that each of the vars are defined. The ones that are currently undef should be defined with an empty string or with 'NULL'. There are a couple ways to do that, here's one:

$FROM_URL = 'NULL' unless defined $FROM_URL;


$FROM_URL = '' unless defined $FROM_URL;