It's not a secret anymore!
The moose likes JDBC and Relational Databases and the fly likes Connection con; 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 "Connection con;" Watch "Connection con;" New topic

Connection con;

purushotham singam

Joined: Aug 23, 2007
Posts: 8
Hai members,
First of all thanking you to all of members to sending response to
my previous doubts.

actually Connection is a interface but we can write in this way

Connection con;
interface we cant create object;
Manuel Leiria
Ranch Hand

Joined: Jul 13, 2007
Posts: 171
And the question is?

Manuel Leiria<br /> <br />--------------<br />Peace cannot be kept by force; it can only be achieved by understanding. <br /> Albert Einstein
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
Connection is an interface.With a reference of type Connection you would actually point to an implementation of Connection interface.

Rahul Bhattacharjee
LinkedIn - Blog
Jan Cumps

Joined: Dec 20, 2006
Posts: 2565

Connection con;
interface we cant create object;
You are not creating an object in this statement,
You are declaring a variable con that can later hold an object that implements the interface Connection.

Later in your code, you will not use: con = new Connection(), but something else.
What are you doing: you are asking your database driver to give you an object that implements the Connection interface.

It's a good idea to set a breakpoint in this line of code, and see what class this object actually is.

Regards, Jan

[corrected my typo: Connection class - doh]
[ August 27, 2007: Message edited by: Jan Cumps ]

OCUP UML fundamental and ITIL foundation
I agree. Here's the link:
subject: Connection con;
It's not a secret anymore!