[Logo]
Forums Register Login
jdbc-2 loading driver
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?
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.
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).
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.
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.")
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.
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>
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:
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...
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 ]
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 ]
yeah I'm not sure London was where I wanted to be when the heat hit! Even the pavements are melting.
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
"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!
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
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*
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 ]
when the control servlet inits
sounds like what i did... it passed, but it was not *exactly* like the real solution.
Wink, wink, nudge, nudge, say no more ... https://richsoil.com/cards



All times above are in ranch (not your local) time.
The current ranch time is
Nov 17, 2017 18:08:32.