This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JDBC-2a Looking for a hint

 
Mark Beattie
Greenhorn
Posts: 26
  • 0
  • 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: 9059
12
  • 0
  • 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: 1202
  • 0
  • 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!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic