• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How can we create object of Connection Interface.

 
Satyajeet Kadam
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
  • 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?


 
Paul Clapham
Sheriff
Posts: 21583
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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).
 
vijin das
Ranch Hand
Posts: 129
Firefox Browser Java Tomcat Server
  • Mark post as helpful
  • send pies
  • 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...



 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic