• 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

Database connection method

 
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all after getting all of the otherthings that I have been working on to work I am now facing the task of pulling in live data from the database. I can make a viable connection within the action form, but that just strikes me of bad design. I am trying to find out the best manner in which to create a connection to the database. I am currently using the BasicDataSource as it is defined in the struts-config.xml, but wanted to know if there is a better way of doing this (the reason I ask is the only way that I have found to get a connection in my database classes is to pass in the request object so that I can pull out the datasource - can someone point me to a good reference on current manners of connecting to a db.

Thanks once again for all your help on the matter.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would strongly discourage you from using the Struts datasource utility. The best practice for all J2EE applications is to set up the DataSource as a JNDI resource using your application server's DataSource setup interface and then to lookup the datasource in JNDI in your applicaiton code.

You might also consider using the Data Access Object (DAO) pattern for your data access. This is one of the core J2EE patterns defined by Sun.

If you're using Tomcat, this link explains how to set up DataSources. If you're using some other application server, consult the documentation specific to the server you're using.
 
A knibbs
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks that is what I was looking for, for some reason JNDI completely escaped my mind.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic