Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Internal technique about initialize Connection Interface in JDBC

 
Rahul Kumar Tiwari
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In one of the interview faced by me recently, an interviewer asked me Connection Interface of JDBC is a Interface and we cant make the object of interface the how we initialize the object of connection using DriverManager Class like this
Ex:-


Please explain me the answer of the above question...
 
Ireneusz Kordal
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

we can't make an object of an interface, but we can create an object of a class that implements this interface.
You can find an explanation how DriverManager.getConnection works in the JDBC specyfication:
http://jcp.org/aboutJava/communityprocess/final/jsr221/index.html
getConnection — the method the JDBC client invokes to establish a connection.
The invocation includes a JDBC URL, which the DriverManager passes to each
driver in its list until it finds one whose Driver.connect method recognizes the
URL. That driver returns a Connection object to the DriverManager, which in
turn passes it to the application.

DriverManager just passes the URL to each registered driver, if one driver accepts the url, then this driver creates a connection object
(that implements Connection interface) and returns this object to the driver manager.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic