aspose file tools*
The moose likes JDBC 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
Bookmark "Object of Interfaces" Watch "Object of Interfaces" New topic
Author

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
Bartender

Joined: Dec 20, 2006
Posts: 2495
    
    8

It returns an object that implements Connection.

Regards, Jan


OCUP UML fundamental and ITIL foundation
youtube channel
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30309
    
150

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


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Object of Interfaces