• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Connection con = new Connection()

 
Sharaj Anand
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I would like to know that in JDBC Connection class why we are not creating it's object like

Connection con = new Connection();

instead of

Connection con = DriverManager.getConnection();

bye
 
Shailesh Chandra
Ranch Hand
Posts: 1082
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Connection is an Interface and you can not instantiate it

Shailesh
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
More specifically, the implementation of the Connection interface is provided by the JDBC driver.

JDBC uses the Dependency Injection pattern so that your code doesn't need to depend on the JDBC driver implementation.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic