How can we make objects of connection when connection is an interface.e.g. Connection conn = DriverManager.getConnection ????

Showing Answers 1 - 8 of 8 Answers

masarrat

  • Jul 26th, 2006
 

Connection is used for getting a physical connection with database;

well there is no need to make any object of Connection. we simply get a reffrence of the database in con.

i.e.

Connection con = DriverManager.getConnection(url,user,pass);

u must know the diffrence between making an object and getting a refrence. than only u can understand this thing.

  Was this answer useful?  Yes

Srinivas Gorityala

  • Aug 10th, 2006
 

Connection con=DriverManager.getConnection (URL, user, password);

 

In the above statement  getConnection() method  is invoked on an object, the object of that class implements Connection interface, here vendor decide the class which is going to be implement the interface, it varies from vendor to vendor,

 

but according to core java concepts we can create an object of an interface when a method is invoked on that particular object of that particular class which is implementing that interface.

So here we can happily create object for connection interface.

 

  Was this answer useful?  Yes

Jaishankar

  • Nov 10th, 2006
 

hi,

  can you be clear about this answer.

  is it that connection interface is being implemented by the vendor in the jar Files they provide.If so wht class it will be.

Thanks in advance

Regards

Jaishankar

  Was this answer useful?  Yes

sambasiva

  • Dec 11th, 2006
 

 

hi jaisankar

 In fact, it is the responsible of driver vendor to provide implemention class for connection interface. Collection of these type classes called as drivers. This class name changes from vendor to vendor. when

Class.forName(DriverclassName);

is executed, the JVM will registe the drivers and

when

Connection con = DriverManager.getConnection(String url,String user,String password);

executed, the JVM  create object to Connection Interface based on the class which is provided (By driver Vendor) as implementation of Connection Interface.

I hope this clear

for enquiry mail to ksr_bmengg@yahoo.co.in

thank u all

sambasiva

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions