Link to home
Start Free TrialLog in
Avatar of Envoy2064
Envoy2064

asked on

Win32::ODBC connection in Tomcat/Perl

Hi,
   This is related to several other cases I've posted on EE about trying to run a Perl program in Apache Tomcat server that connects to a database. The essence of the problem is: I can run the Perl program just fine from command line, but when I try to run it in Tomcat, it just doesn't finish processing. Apparently, after inserting many debugging lines, the reason why it stalls is the following code:

$myDB = new Win32::ODBC($data_services) // this line runs fine if i execute Perl from command line, but stalls in Tomcat

is there any way to resolve this issue? Any help will be greatly appreciated. Thanks!
Avatar of Envoy2064
Envoy2064

ASKER

Also, on the following page: http://tomcat.apache.org/faq/database.html

It says:

    *   Do not use JDBC-ODBC bridge bundled with Sun's JDK with Tomcat. It was never meant for a production server environment. If you ask a question about it, everyone will tell you to not use it. If you do need to use ODBC, there are 3rd party drivers which do a pretty good job at being thread safe.
    * If you use the oracle thin driver, be sure to rename it to a jar file from a zip file. Tomcat only auto-magically loads files ending in .jar placed in a lib directory. It ignores all other file extensions.

I'm not sure what this means for my problem here...
Upped the point value. Any ideas? :-)
Does the data source work in plain java command line?
It is not thread safe just like many other type4 JDBC drivers.
gheist, can you please explain more about thread safe for the JDBC drivers? Are you saying that the Tomcat/Java app server disables connections that are not thread safe?

Upped the point value again...

Thanks!
Any error that signifies connection disabled?
Post the code, please.
No error at all, the Tomcat app just keeps running and hanging there...
WHERE IN THE CODE?
At the following line:

$myDatabase = new Win32::ODBC($data_source);
Does it fail same way in plain java application?
Command line to stalled perl interpreter using "Process Explorer" from www.sysinternals.com.
Does it run same way outside tomcat?
No, outside of Tomcat, the perl.exe process runs just fine and finishes in < 3 seconds.

Perl.exe is the process that's stalling while executing the perl script, as seen from the Task Manager...
Download "Process Explorer" program and examine perl command line and environment of stalled perl launched from Tomcat.
I did what you suggested, and didn't see anything unusual in the Perl environment tab. However, in the Threads tab, I see something like "Wait:WrUserRequest"...seems to me it can't get into database?
Seems it tries to open input and read ?nothing?
Are you using Sun's JDK?  From your first comment (after the original question), it sounds like this could be the problem.
Does the cgi run inside Apache webserver?
Adam -- yes, I'm using the Sun's JDK to power the Tomcat server. Why would it be a problem?

gheist -- yes, the cgi runs in Apache webserver. I had some problems running CGI at first but after researching the web I found a way to make CGI run in Tomcat/Apache.

Changed point-value again. Thanks.
I'm not sure why... but your first comment says you shouldn't use those in combination:
*   Do not use JDBC-ODBC bridge bundled with Sun's JDK with Tomcat. It was never meant for a production server environment. If you ask a question about it, everyone will tell you to not use it. If you do need to use ODBC, there are 3rd party drivers which do a pretty good job at being thread safe.

You might need either a different database driver or a different JDK.
Please mention version of perl interpreter, JDK and Tomcat server. I had enabled Activestate perl and it opens database connections from inside tomcat 5.5 just fine BEA Jrockit 6.0 win32
Hi gheist, that would definitely help if you could tell me how you did it. :-)

java -version results in: 1.6.0_03

perl -v results in: 5.8.8

Tomcat: 5.5.25
I was just thinking that it may be that the Perl script can't read the configuration file on the tomcat server that lets it get *into* the database....how can I be sure that it can access the configuration file w/ the username and password?
Also, is it possible to create a Java program that calls the Perl script *from the command line*? So the Perl script would effectively be running in the command line, not in the cgi-bin of the Tomcat server...
%WINDIR%\SYSTEM32\CMD.EXE /C C:\PERL\BIN\PERL.EXE -W SCRIPT.PL
Sun/BEA/IBM JDK?
Cygwin perl or ActiveState or something else???
using JNI?
Example:
1) java -version
java version "1.5.0_13"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_13-b05)
Java HotSpot(TM) 64-Bit Server VM (build 1.5.0_13-b05, mixed mode)
2) perl -v
This is perl, v5.8.8 built for x86_64-linux-thread-multi
Using exec(), sir. Tomcat calls native CGI executable.
Okay, I'm going to try your approach, gheist...but one more thing: how can I pipe the output back to the browser?
ASKER CERTIFIED SOLUTION
Avatar of gheist
gheist
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial