File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Spring in Action this week in the Spring 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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Using Tomcat datasource from command line?