• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Connecting to MySQL locally via JNDI

 
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,

I'm using a Tomcat 5.5.17, MySQL DB and and JSP's at this point in time, possibly changing to JSF.

What I've acheived currenlty is to use the code below (and some more) to connect to a DB - i.e.just java-database (no webserever)


On the Tomcat I'm using JNDI. I want to do the same locally, rather than use two distinct methodologies and then cut/paste code etc.

Does anyone know of a good code examples on how I could use JNDI locally i.e. between java-mySQL database (not using the browser).

Thanks in advance for your views
Zein
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This sounds like a good idea, except there's only one problem: To use JNDI, you have to have a server that supports JNDI running or your JNDI lookup will fail. This means you're making your stand-alone java application so that it won't run unless a JNDI server is running. Not such a good idea.

With some good OO-Design, it's not that hard to design a flexible solution. Create an interface for a service that gets a database connection. Then create two different implementations of that interface -- one for JNDI and one for stand-alone Java. In your application code, you'd then code to the interface rather than the implementation.
[ March 03, 2007: Message edited by: Merrill Higginson ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic