Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using Tomcat datasource from command line?

 
Gary Seibold
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic