aspose file tools*
The moose likes JDBC and the fly likes How can we create object of Connection Interface. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How can we create object of Connection Interface." Watch "How can we create object of Connection Interface." New topic
Author

How can we create object of Connection Interface.

Satyajeet Kadam
Ranch Hand

Joined: Oct 19, 2006
Posts: 215
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
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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

Joined: Jun 07, 2010
Posts: 129

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...




VIJINDAS
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How can we create object of Connection Interface.