File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Lots of Doubts in JDBC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Lots of Doubts in JDBC " Watch "Lots of Doubts in JDBC " New topic

Lots of Doubts in JDBC

Rushi Patel

Joined: Sep 14, 2011
Posts: 17

In this code we know Connection and Statement are INTERFACE...
So their reference (con / stmt ) holds whose Object ???

I have mainly three question for these statements ::
------------------------------------------------------------------------- [/size]
  • Which class implement this Statement and Connection interface ???

  • What are drivers ?? ex:: "com.jdbc.odbc.JdbcOdbcDrivers"
    Is it PACKAGE ???

  • If its package than why we cant just import them ???
  • Tim Holloway
    Saloon Keeper

    Joined: Jun 25, 2001
    Posts: 17417

    The whole point of having an interface is that it allows plug-in replacement components instead of a particular class. The DriverManager parses the JDBC URL and attempts to determine which specific class it's going to use.

    For example, a "jdbc:mysql" URL will pair up with the org.mysql.Driver class (class names and URLS are illustrative only and may vary). A "jdbc:db2" URL will pair up with a "" class. Some DBMS's have more than one Driver class for various reasons, so they may support more than one URL format.

    Just like the Driver, the Statement and ResultSet classes are interface classes. That's because the concrete realizations of those classes depends on which database driver is in use, since the class implementations are part of the driver itself and hold driver-internal resources.

    As a rule, you should never attempt to obtain the actual concrete class reference for JDBC, and only work with the interfaces. An exception to that rule is the case where, for example, you need access to data types not supported by JDBC that are supported by Oracle or PostgreSQL. You'd then cast the returned interface reference to the underlying class so that you could access these non-portable functionalities.

    An IDE is no substitute for an Intelligent Developer.
    I agree. Here's the link:
    subject: Lots of Doubts in JDBC
    It's not a secret anymore!