• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

jdbc-2 loading driver

 
Sheriff
Posts: 4012
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm about to go at my second attempt, but thought I should check in to make sure I'll be heading down the right path (or close to it).
In ListVideoServlet and AddVideoServlet I connect to the db, first loading the driver each time with
Class.forName( "com.mysql.jdbc.Driver" ).newInstance() ;
This won me a couple nitpicks about creating a new instance each time this class is used. From this discussion about using newInstance I assume that we shouldn't just drop newInstance. So, that makes me think the driver should instead be loaded elsewhere, once - at least that's what I was planning to try next.
Am I warm?
 
whippersnapper
Posts: 1843
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
PM: I assume that we shouldn't just drop newInstance.
Why not? What would you use if for? (Take a brief look at the Driver interface and DriverManager class APIs to see what they do.)
So, that makes me think the driver should instead be loaded elsewhere, once - at least that's what I was planning to try next.
Am I warm?

This part, yes, I believe. Load/register the driver once, then open and close connections as needed.
 
Michael Matola
whippersnapper
Posts: 1843
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Second thought.
When you said
drop newInstance
Did you mean "drop newInstance()" or "drop the new instance created by 'newInstance()'"? My response assumed the latter (perhaps mistakenly).
 
Pauline McNamara
Sheriff
Posts: 4012
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mike.
Did you mean "drop newInstance()" or "drop the new instance created by 'newInstance()'"? My response assumed the latter (perhaps mistakenly).
By "drop newInstance()" I meant write
Class.forName( "com.mysql.jdbc.Driver" ) ;
instead of
Class.forName( "com.mysql.jdbc.Driver" ).newInstance() ;
The first way "should" work, but apparently doesn't always ( as covered here).
I am warm. Heat wave over here.
 
Michael Matola
whippersnapper
Posts: 1843
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, I mistakenly thought you were asking something along the lines of:
Instead of the following
Class.forName( "com.mysql.jdbc.Driver" ).newInstance() ;
Should I store a reference to the object that gets created:
Object reallySomethingThatImplementsDriverIPromise = Class.forName( "com.mysql.jdbc.Driver" ).newInstance() ;
So that's what my "Why? What would you use it for?" was in response to. (Now having read the discussion you linked to I guess I would recast my response as "Not unless you plan to manually register the driver like Jim shows in one of his examples.")
 
Michael Matola
whippersnapper
Posts: 1843
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Heat wave over here
Yeah, tell them to cool it down. I'll be in Barcelona and Madrid in September. Don't want to fry.
 
Pauline McNamara
Sheriff
Posts: 4012
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hopefully by then it will be reasonable again. I can't imagine what it's like to be south now. Portugal is suffering from big fires. Actually what we're having up here is probably much like what it's normally like down there. I'm just not made for this kind of weather.
<poor wicked witch imitation>I'm melting! I'm me-e-e-llting!</poor wicked witch imitation>
 
Chicken Farmer ()
Posts: 1932
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wow, Pauline's still alive!? A messy puddle of a Pauline, but still Pauline
And gee Mike, sure would hate to be you... roller blading in the Rockies, travelling all over Spain... geez :roll:
 
Pauline McNamara
Sheriff
Posts: 4012
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ew, what's that smell - hey! who let the chicken farmer in?
Jason, could you please leave your boots at the door when you come in from the barnyard, you're tracking all kinds of **** around here...
 
Michael Matola
whippersnapper
Posts: 1843
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JA: And gee Mike, sure would hate to be you... roller blading in the Rockies,
Skating in the Rockies? That is so last summer! :roll:
(Actually in terms of pure fun, that was one of the best vacations I've ever taken. Highly recommended. Too bad I didn't have time to do it again this year.)
travelling all over Spain
Well not all over Spain. We're saving the south for another time.
Oh, and you missed a trip in between Colorado and Spain.
(Won't jinx things by mentioning what else is in the works for this fall...)
... geez :roll:
Coupla standard responses to that:
(1) I list "travel" as an interest on my resume. Now wouldn't it make me a damn liar if I didn't actually do it?
(2) Geez, look at Michael not having cable TV, so he has more money for travel. Buying a cheaper car, so he has more money for travel. Living very modestly in general, so he has more money for travel. (Starting to see a pattern?) Just depends on what you want to do. (I mean, this former coworker of mine gave me a hard time (jokingly) once about my vacations. Turns out this woman's little hobby was having her nails done every other week at $25 a pop. That's friggin' $650 a year spent ON HER FINGERNAILS! I see an extra $650 a year as a round-trip ticket to somewhere fun.)
(3) Not having a house, kids, pets, or plants makes getting up and going somewhere a lot easier. (Not to mention not having a working farm.)
(4) Travel is *not* that expensive. Or, maybe let me rephrase that: the more you do it, the better you get at doing it cheaply.

----
"I just wanted to get the hell out of Michigan." -- M.L. Ciccone
[ August 07, 2003: Message edited by: Michael Matola ]
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
After this HOT weather here in yourrope, there must be umpteen billion tons of water up there somewhere. Now, do you remember that famous musical "My Fair Lady"? The bit where Eliza sings "The rain in Spain falls mainly on the plain"?
I need say no more.... take your rubber duck!
[ August 07, 2003: Message edited by: Barry Gaunt ]
 
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yeah I'm not sure London was where I wanted to be when the heat hit! Even the pavements are melting.
 
jason adam
Chicken Farmer ()
Posts: 1932
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh c'mon Michael, break into a musical for us!

Pauline, just because you're on the active list doesn't mean you're all that
 
Pauline McNamara
Sheriff
Posts: 4012
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"I just wanted to get the hell out of Michigan." -- M.L. Ciccone
LOL
Now there's a man (MM) with his heros in the right place!
 
Michael Matola
whippersnapper
Posts: 1843
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JA: Oh c'mon Michael, break into a musical for us!
Show tunes? How about this instead.
My work has a *very* generous vacation benefit for a US employer: I get 24 discretionary vacation days a year. And you can accumulate a reserve of 48 days before you start losing them. The are quite a few people in my office who are at their vacation max and they actually *loose* vacation days. Can you imagine?
When people mention (brag?) about being at vacation max, I often break into song. The song of choice is "That'll Never Be Me" from Say Anything.

That'll never be me, that'll never be me.
That'll never be, never be me.
NO!
NO, NEVER, NEVER, EVER!
And don't you EVER THINK IT!

Michael "I don't want to sell anything, buy anything, or process anything..." Matola
 
jason adam
Chicken Farmer ()
Posts: 1932
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Now do it on skates... sans the hot pants, of course.
And the funny thing Pauline, I was at a meeting yesterday and someone actually pointed out that I had something on the bottom of my boot. Seems I hadn't fully scraped off everything when I fed the critters in the morning
And don't knock Michigan, I know some really excellent Uppers, though the Trolls are rather hard to be around sometimes
*lifts his mug of hot chocolate and grins*
 
jason adam
Chicken Farmer ()
Posts: 1932
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And to get back on topic, one trick I learned dealing with servlets, jsp, and Struts, is to load the driver when the control servlet inits, and to create a Connection object and stick it in the servlet context. From there, anything that has access to a request object, or session object, can get the Connection and do whatever JDBC stuff is needed.
This isn't the best way to do things, but if you are working in an application that is all Presentation tier (which unfortunately there are some out there), it's handy.
[ August 08, 2003: Message edited by: jason adam ]
 
Ranch Hand
Posts: 1012
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
when the control servlet inits
sounds like what i did... it passed, but it was not *exactly* like the real solution.
 
Too many men are afraid of being fools - Henry Ford. Foolish tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic