aspose file tools*
The moose likes Cattle Drive and the fly likes JDBC-2a Looking for a hint Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "JDBC-2a Looking for a hint" Watch "JDBC-2a Looking for a hint" New topic
Author

JDBC-2a Looking for a hint

Mark Beattie
Greenhorn

Joined: Mar 30, 2006
Posts: 26
My VideoServlet application uses a JDBC Connection object. It is very naughty of me to use this Connection as a global variable.

One solution:
Should I change the argument lists of all methods that use a connection object. For example, in the AddActionHandler there is a method called doSecureAction(ServletData servletData). Should I overload this method to take a Connection object?

Or is there a more elegant solution that I should consider?

Any hints would be greatly appreciated.

Thanks,

Mark
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9052
    
  12
It is very naughty of me to use this Connection as a global variable.

A global Connection is a bad idea. Some day you're gonna have to think along the lines of thousands of users at once.

Should I change the argument lists of all methods that use a connection object.

Would you still be using the same connection for each of those methods? Would it be better to get a new connection each time you need it and release it while you're doing other things that don't require a connection so someone else can use it?


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Carol Murphy
village idiot
Bartender

Joined: Mar 15, 2001
Posts: 1197
I had the same nit pick when I did this assignment, not more than a few weeks ago. It eluded me until the last, and Marilyn had to practically rub my nose in the solution before I saw it. The answer is one of those things that is so simple, and it becomes incredibly obvious after you've tripped over it!
I will search for one of my posts!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JDBC-2a Looking for a hint