• 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

where dose code of geting connection should put?

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have code that is related to connection pool.
Context ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup("java:comp/env/jdbc/myoracle");
conn = ds.getConnection();
Many of struts's action need call it.
I know 2 ways.
1) Codes is written in every action that use it.
2) encapsulating code into one class's static method.then every action class all call the class'static method
using 1), I fell CODE is redundancy!
using 2), when many user access application,if encapsulating class is single thread, performance will be bad.
or,if I have other choice?
Thanks
[note]: Basically I Don't intend to use mutiple-tie structure,so I directly wirte sql into action class
 
author & internet detective
Posts: 41878
909
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Liang,
You should try to avoid code redundancy as much as possible. A third alternative is to put the common code in an action superclass which your actions all extend. The new action would extend struts' action class.
A fourth alternative is to put all the data access code in a separate class. The action could instantiate this class and call it. There isn't a need to rely on a static method.
 
reply
    Bookmark Topic Watch Topic
  • New Topic