Database connection on linux

Hi,

I have a JAVA web application running on Linux which works fine.  The connections are taken from the tomcat (web-server) connection pool.  

The problem is, there is a scheduled task which needs to bew run, using cron, every day.

It runs, but it does not use the connection from tomcat, because (I think) it is not running in hte web-server environment.  It is a mysql database.  Is there any other way to connect so that I can avoid this problem, such as having a global datasource?
 
rosshindAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

girionisCommented:
> It runs, but it does not use the connection from tomcat, because (I
> think) it is not running in hte web-server environment.  It is a mysql
> database.  Is there any other way to connect so that I can avoid this
> problem, such as having a global datasource?

You will need to simulate the web application somehow in order to use the conenctions from Tomcat's database pool. You can have a utility task that acts like a datasource if you want though. This class will be used by Tomcat and any other application that needs access to the database, but you will have to manualyl create the pool and the connections since it woudl be Tomcat-independent.

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
lhankinsCommented:
What is the scheduled task written in...?   Is it a shell script...?   Is a java program...?

If it is a java program, you could move the code into your webapp and have it executed from within your servlet container.   For example :

1. Modify the code to use the same datasource lookup connection parameters your webapp does.
2. Expose a hook which kicks off this code via url (either kick it off from a JSP/Servlet, add a struts action which kicks off the code, etc).
3. Adjust your cron job to just hit the URL in your webapp (instead of running the script manually).

0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

objectsCommented:
Instead of using cron you could load a servlet on wtartup of your webapp that uses a Timer to run the task (from the webapp).
0
girionisCommented:
I believe I provided a general idea of what should be done and was expecting the user to come back for a more specific question in order to help more. I think I deserve some points.
0
kiranhkCommented:
I gave the link to the proper documentation on setting up the Datasource and accessing them !!!
 I think I also deserve some points.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.