• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

JDBC: What is the concrete class that implements the jdbc interfaces  RSS feed

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In a jdbc code, I am mentioning a sample code below for our reference, we come across
Connections, Statements, PreparedStatement, ResultSet. All these are interfaces. In which part of the jdbc code are we coming across a concrete class. We cant execute a code without a concrete class, by just using interfaces. I am not able to identify what class is the real concrete that is executing this jdbc code.


 
Marshal
Posts: 67164
169
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's the whole point of interfaces -- you don't want or need to know!
 
Rancher
Posts: 42974
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Somewhere you have a jar file that contains the MySQL JDBC driver - the classes that implement those interfaces are in that jar file.
 
author
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why not add a line such as:

System.out.println("conn is a " + conn.getClass());

That should tell you the concrete class implementing that interface. You can do the same for the other interfaces.

The "magic" behind the way that JDBC works is that you ask the DriverManager for a connection using a URL. The DriverManager gives you a concrete class that implements the Connection interface. You then turn around and ask the concrete class that implements the Connection interface for a Statement, so that concrete class returns another concrete class that implements the Statement interface. Notice that in this whole scenario that you never "new" anything (that is, you never write "xxx = new XXX").
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!