Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Driver wanted

 
Carol Murphy
village idiot
Bartender
Posts: 1203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is for a Cattle Drive assignment, so I can't post a lot of code. I've got a database that I want to access for purposes of displaying a list of videos in table format. (My code works, but it has issues.) Currently I put the code for loading the driver inside the block of code that handles the login. My reasoning for this was that once the login is successful, I want my app to display the list of videos stored in the database, and in order to do that, I have to have access to the database.
Apparently, this is a poor choice. My nitpicker made a reference to a popular website that has thousands of people logging in every few minutes, and I guess loading the driver with each login is bad. I just don't know why.
What is the issue with loading the driver? When should it be done, and for what reasons?
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a bit of overhead associated with loading the driver, so in general it should be avoided simply in order not to do something repeatedly that acoomplishes nothing. Having said that, I don't think the overhead of Class.forName is sizeable, because once the class (and driver) is loaded, the next call will determine that it is loaded already, and not do anything else.

Generally the driver initialization should be done during application startup, e.g. in Servlet.init if this is a web app.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic