• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How can an interface reference invoke a method

 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
Please help me understanding the following concept, am having a hard time with it.

consider the following code:

Connection connection = DriverManager.getConnect
 
amal shah
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
Please help me understanding the following concept, am having a hard time with it.

consider the following code:

Connection connection = DriverManager.getConnection("string");

Now to have a connection object,there should be some class implementing methods of connection interface,and in turn object to that class is returned to "Connection" interface reference

When i looked into DriverManager class,for getting a reference to Connection,there is a native method call. Does it mean at RunTime there is some class implementing Connection interface in order to get a Reference.

So how does it all happen.

help appreciated
cheers
amal shah
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Depending on the connection string you pass, the DriverManager looks up a Driver implementation. This implementation is provided by the database vendor or some third party. For instance, MySQL, Oracle and MS SQL Server each have their own drivers, whereas for Access and ODBC you can use drivers written by Sun.

These drivers will be accompanied by a number of classes that implement interfaces such as Connection, Statement, ResultSet etc.


The thing is, the java.sql model is designed in such a way that you don't need to know what the actual classes are. You'll use the interface declarations everywhere, which allows for fast changing to a new database system - change the connection string, load the correct driver, and you're ready to go.
 
amal shah
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

This implementation is provided by the database vendor or some third party.



But,where does the implementation reside. Where actually is that class file.
I see many Interfaces in the API with similar concept as that of Connection Interface. But where does the implementing class resides.

help appreciated
cheers
amal shah
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Amal:

In the jdbc driver's jar file, if that is what you want to know. For example for mysql it will be mysql-connector-java-xxxxxx.jar file.
This jar file is in your classpath.

HTH.
mani
 
God is a comedian playing for an audience that is afraid to laugh - Voltair. tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic