• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JDBC-2a Looking for a hint

 
Mark Beattie
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9065
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Carol Murphy
village idiot
Bartender
Posts: 1203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic