If you are accessing one type of database, such as Oracle, Sybase, or IBM, the preferred driver type is 4.
If your Java application is accessing multiple types of databases at the same time, type 3 is the preferred driver.
Type 2 drivers are useful in situations, where a type 3 or type 4 driver is not available yet for your database.
The type 1 driver is not considered a deployment-level driver, and is typically used for development and testing purposes only.
Sometimes the only way things ever got fixed is because people became uncomfortable.
Paul Crane wrote:You wrote that the JDBC bridge has been removed, so there’s no need to use that?
Paul Crane wrote:so I have to download the jars with all the classes, or use Maven to automatically download them while runtime
Sometimes the only way things ever got fixed is because people became uncomfortable.
Sometimes the only way things ever got fixed is because people became uncomfortable.
Paul Crane wrote:Okay. I fully don’t understand the Driver/DriverManager usage. It has to be a part of JDBC. So they’re contained within the jars?
Sometimes the only way things ever got fixed is because people became uncomfortable.
Paul Crane wrote:DriverManager is used for connecting to a database, but it has to "find" the right driver? Wow. I do just write the getConnection() method, and then write the URL inside. Something must be under the hood?!
Sometimes the only way things ever got fixed is because people became uncomfortable.
Paul Crane wrote:So I don’t have to install something more because it’s already been in the jars.
So drivers are classes implementing the JDBC interfaces
and contained inside the API
During the getConnection(), the DriverManager looks on the URL and takes the particular downloaded driver?
That's no longer true, as there's a special entry in the MANIFEST of the JDBC driver JAR that tells the JVM to make the connection, so Class.forName is not longer needed (it's relatively harmless to keep it, just shows someone's out of date)
There are lots of examples of out of date code out there. I still see the use of...which wasn't even properly correct code before try with resources back in 2009.Paul Crane wrote:. . . I see lots of examples where people still use Class.forName()
Campbell Ritchie wrote:
There are lots of examples of out of date code out there. I still see the use of.Paul Crane wrote:. . . I see lots of examples where people still use Class.forName()
Sometimes the only way things ever got fixed is because people became uncomfortable.
The Driver interface defines a method named "acceptsURL". So what the DriverManager can do is enumerate its collection of registered drivers until it finds one where the acceptsURL method returns true for the JDBC URL you've passed to getConnection. Then the DriverManager can invoke that Driver's connect method which will either create the Connection instance that will be returned to the app OR it will return null, indicating that this Driver cannot handle that request and the DriverManager will need to keep searching.
Sometimes the only way things ever got fixed is because people became uncomfortable.
Paul Crane wrote:I don't know whether I should understand it fully or not, but just want to.
Paul Clapham wrote:
There seems to be this idea going around which claims that understanding how something works internally makes you a better person somehow.
Sometimes the only way things ever got fixed is because people became uncomfortable.
Stephan van Hulst wrote:Modern-ish libraries will contain a folder META-INF/services that contains a file named java.sql.Driver, that contains the names of the classes that implement the Driver class.
Modern libraries contain a module descriptor module-info.java that contains a provides declaration.
Sometimes the only way things ever got fixed is because people became uncomfortable.
Sometimes the only way things ever got fixed is because people became uncomfortable.
Here. Have a potato. I grew it in my armpit. And from my other armpit, this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
|