File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes  jdbc statment creation 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 " jdbc statment creation" Watch " jdbc statment creation" New topic

jdbc statment creation

amrut sabade
Ranch Hand

Joined: Aug 16, 2010
Posts: 90
Hi everyone we learned in core java that we can't create an object of Interface,... and in jdbc statment is an and interface so how do we create an object of statement?
please clear my doubt
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

We don't, unless we are JDBC driver writers. Interfaces need implementations otherwise you can't use them. The JDBC driver provides implementations of all the JDBC interfaces for whatever database it connects to. When you call createStatement() its the implementation that is returned. Try writing:

to find out what that implementation is.

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46349
I think whoever said "can't create an object of an interface" has misunderstood implementation. You can create an object of an interface, but indirectly, by implementing it. You can create a class which implements that interface, either as an ordinary (concrete) class or an anonymous class. Remember you can do this in several stages in an inheritance hierarchy, some of which stages might be abstract classes or other interfaces.Here the Statement object "hides" an implementation of the ResultSet interface which is what is actually returned. So the statement implements the interface ResultSet and returns an object of that implementation, which is an object of ResultSet. Have a look at my Engine and GrowingPlant examples from three years ago. Read that discussion. Find the lineand change it toChange "Tree" to "GrwoingPlant" in all the for-each loops. See whether you can see any difference in the output.

Ad a few lines to the original classesAdd a new classNow see what happens. Every member of the "trees" array is an instance of the GrowingPlant interface. Create the Lithops class, where the plant grows 1mm taller every time.
amrut sabade
Ranch Hand

Joined: Aug 16, 2010
Posts: 90
hii thank s s o much i got the concept..thanks for giving such a nice explenation
I agree. Here's the link:
subject: jdbc statment creation
It's not a secret anymore!