• 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 we create object of Connection Interface.

 
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Q1) How to create an object of Connection Interface?
Please correct if i am wrong?

1) Interface cannot be instantiated.So we can create a class that implements the interface then create the object of the connection interface.

Q2) I don't understand how DriverManager.getConnection() creates connection object.DriverManager class is not implenenting the Connection interface in API.
Then how the DriverManger class is creating the object?

Q3) If we want create object we normally create class that implements the interface then create the object but How DriverManager class API is creating the object
without implementing the connection Interface?


 
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

amolpalekar kadolkar wrote:Q3) If we want create object we normally create class that implements the interface then create the object but How DriverManager class API is creating the object without implementing the connection Interface?



No. DriverManager returns an instance of a class which does implement the Connection interface. That's all it does. (The class already exists, and it's in the JDBC driver jar.) So asking how it does something else isn't a very useful question (especially since you seem to be claiming it does something which it doesn't actually do, and asking how it does that).
 
Ranch Hand
Posts: 129
Firefox Browser Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Java APIs utilize major design patterns

he classes java.lang.System and java.sql.DriverManager are examples of the Singleton pattern,
although they are not implemented using the approach recommended in the GoF book but with static methods...



 
reply
    Bookmark Topic Watch Topic
  • New Topic