This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes Object of Interfaces Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Object of Interfaces" Watch "Object of Interfaces" New topic

Object of Interfaces

Ankitt Gupta
Ranch Hand

Joined: Feb 19, 2009
Posts: 101
Hi Ranchers

As we know we can't make objects of interfaces.But while writing JDBC codes the getConnection() method returns Connection object...How?
Please clarify this
Jan Cumps

Joined: Dec 20, 2006
Posts: 2542

It returns an object that implements Connection.

Regards, Jan

OCUP UML fundamental and ITIL foundation
Ankitt Gupta
Ranch Hand

Joined: Feb 19, 2009
Posts: 101
Jan Cumps wrote:It returns an object that implements Connection.

Regards, Jan

Thanks for replying Jan
You mean to say that there is some anonymous class that implements it?
Kiran Joshi
Ranch Hand

Joined: Sep 04, 2005
Posts: 54
The implementing class is not required to be anonymous.
It is provided through the jars you keep in your classpath.
for example ojdbc14.jar or classes12.jar provided by db vendors like (oracle) or third parties that provide jdbc drivers.
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 32481

Right. The interface is so you don't refer to the concrete class. That way you can change databases/drivers without changing your code.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Have you checked out Aspose?
subject: Object of Interfaces
It's not a secret anymore!