Win a copy of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications this week in the Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JDBC-1 Connector/J updated ?  RSS feed

 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using Connector/J downloaded from the http://www.mysql.com site and I am using the following code in the testing programs.
Can I suggest that the instructions in JDBC-1 be edited to reflect this change? The invocation of the newInstanceMethod() is not necessary either, it seems.
-Barry
 
Marilyn de Queiroz
Sheriff
Posts: 9081
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'll check out the changes in mySQL. Thanks for the heads up, Barry.

As far as the newInstance() is concerned, it is necessary under certain circumstances (read "certain JVM implementations"). I recommend using it.
 
jason adam
Chicken Farmer ()
Ranch Hand
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree, keeping newInstance() tends to lend to better portability, and I've noticed adds less confusion to the mix. Even at work people are thrown off by a simple forName() method call, whereas newInstance() at least shows that something is being created.
Good call on the package for the Driver, seems to be more "out there" than the org.yada.yada.yada,
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The reason I mentioned this forInstance() thing was the java.sql.Driver API documentation says:
When a Driver class is loaded, it should create an instance of itself and register it with the DriverManager. This means that a user can load and register a driver by calling Class.forName("foo.bah.Driver")
[ April 27, 2003: Message edited by: Barry Gaunt ]
 
jason adam
Chicken Farmer ()
Ranch Hand
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I get leary of any wording in a spec that says "it should", in my experience this usually translates to "most of the time, but not always".
Have to say I haven't experienced negative effects of not using newInstance(), but taking the one or two seconds to tack it on isn't that bad of a habit to be in, and reduces the possibility of problems arising because the vendor didn't do what they should
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My take on this is that if the driver vendor didn't bother to implement something this simple as it was intended to be done, then I really do not want to be using that driver. There are some types of stupidity that are best filtered out at the beginning, rather than trying to cater to them.
 
jason adam
Chicken Farmer ()
Ranch Hand
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Egads, who let him in here!
Good point Jim, it's like working your servlets and JSP to function with a vendor that doesn't abide by the spec. Still, I hate that word "should"
So when's the Boss gonna come in and lay down the law?
p.s. Thanks for locking that post
[ April 28, 2003: Message edited by: jason adam ]
 
Marilyn de Queiroz
Sheriff
Posts: 9081
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Marilyn de Queiroz:
As far as the newInstance() is concerned, it is necessary under certain circumstances (read "certain JVM implementations"). I recommend using it.

This information was found in a book about JDBC/Java (Database Probramming with JDBC and JAVA™ by George Reese). It is not specific to a particular driver. Note that it says JVM, not mySQL driver. Now, JVM's may be vendor specific, but are you sure that everyone will always use the same JVM that you do?
[ April 30, 2003: Message edited by: Marilyn de Queiroz ]
 
Marilyn de Queiroz
Sheriff
Posts: 9081
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It appears that the com.mysql.jdbc.Driver is the new updated version of the org.gjt.mm.mysql.Driver, although both drivers are currently supported.

We'll discuss changing the assignment page.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[jason]: Egads, who let him in here!
Just testing security. Seems pretty lax. You guys probably need to set up patrols of some sort to keep argumentative riff-raff out.
[MdQ]: This information was found in a book about JDBC/Java (Database Probramming with JDBC and JAVA� by George Reese). It is not specific to a particular driver. Note that it says JVM, not mySQL driver. Now, JVM's may be vendor specific, but are you sure that everyone will always use the same JVM that you do?
Hmmm, well maybe. I still want to rant though, and I'm suspicious of the quoted info. Is there any more info provided about the "certain circumstances"? I"m guessing maybe this means "some JVMs have an obscure bug, and the only workaround we've found is to manually instantiate the Driver". I trust the API over a book I'd have to pay money for.
Let's look at it from this perspective - OK, so maybe the API does not require a Driver class to register itself when loaded. Where if anywhere (in the API) is it established that merely invoking newInstance() should be sufficient to get it registered? It seems to me that if we can't trust the Driver class to register itself properly during class loading, we should do so explicitly:

or more simply

The whole Class.forName() thing really only makes sense if you're reading the name from some other source, like a property file, IMO. If you're hard-coding the name, well heck, there are more direct ways to do what you want.
Of course, if we go back to trusting the driver and JVM to behave like God intended , then Class.forName() has the advantage of brevity, and not confusing readers by creating an instance we don't need or use. Using a class literal would have the same effect, forcing the named class to be loaded - but you can't just have a statement like
com.mysql.jdbc.Driver.class;
because it's "not a statement". The compiler wants you to do something with it. So in this case, Class.forName() makes a little more logical sense, in that it is a statement that merely forces a class load, nothing more.
 
paul wheaton
Trailboss
Posts: 22574
Firefox Browser IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Marilyn asked me to look in here.
I think Jim is right and I simultaneously think we should leave the "newInstance()" thing. Mostly cuz I copy that code when I get to a new gig and need to load the driver. I don't wanna mess with thinking about this again. Bosses want stuff to work and work fast, not have a guy like me whining about how the driver sucks.
As for the class name: if the new one works, I like it better!
Marilyn, could you please make the appropriate changes?
[ May 01, 2003: Message edited by: Paul Wheaton ]
 
Marilyn de Queiroz
Sheriff
Posts: 9081
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Paul Wheaton:
Marilyn, could you please make the appropriate changes?


Done
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!