• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Lots of Doubts in JDBC

 
Rushi Patel
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
    Pie
    Posts: 18098
    50
    Android Eclipse IDE Linux
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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 "com.ibm.db2.jcc.Driver" 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.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic