This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Tomcat and the fly likes Using Tomcat datasource from command line? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Using Tomcat datasource from command line?" Watch "Using Tomcat datasource from command line?" New topic
Author

Using Tomcat datasource from command line?

Gary Seibold
Greenhorn

Joined: Oct 08, 2004
Posts: 7
I have a web app running on Tomcat 5.5 that uses a datasource set up in the apps xml file in conf.Catalina/localhost.

I now want to also run a java class in that web app from the command line and have it access that datasource. I added a jndi.properties to WEB-INF/classes with




When I run the clas from the command line I get
Name java:comp is not bound in this Context

This is the connection code that works from the web app.



I also get Name jdbc is not bound in this Context if I use DataSource dataSource = (DataSource)_initialContext.lookup("jdbc/test")


Can I use a Tomcat's datasource from a class run at the command line? How?

Thanks.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

No, but in our CodeBarn, there is a JNDI helper library that I use for this.
Once configured, all you need to do is add a couple lines to your main method to initialize the wrapper before trying to call your database code.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using Tomcat datasource from command line?
 
Similar Threads
javax.naming.NamingException: Cannot create resource instance
provider_url for datasource
Unit testing using dbunit
How to Reuse JDBC connectivity code in other Java programs or classes?
How to Resolve this exception in tomcat 5.0.28