Win a copy of Head First Android this week in the Android forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Single Database connection

 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would like to create a single Database connection point that I can use for 4 classes in my Java Web Application.

Here is my ConnectionManager Class:


Now how would I access this in each one of my classes?

For example here is one:



Another Class looks like this:


Please advise.
[ October 17, 2007: Message edited by: Dan Parsons ]
 
Ranch Hand
Posts: 212
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You don't need to pass connection from one class to another,
Instead whenever you need a connection in any of your class just call
ConnectionManager.getConnection() and it will return the active connection.

IF classes are going to be used by more than one threds, make the threadlocal connection inside ConnectionManager.
 
Ranch Hand
Posts: 341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

You don't need to pass connection from one class to another



If your application need a transaction among the classes, you need to pass the connection through and set autocommit to false.
 
reply
    Bookmark Topic Watch Topic
  • New Topic