File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Connection is a interface & so how can we access it createStatement() on con object? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Connection is a interface & so how can we access it createStatement() on con object?" Watch "Connection is a interface & so how can we access it createStatement() on con object?" New topic
Author

Connection is a interface & so how can we access it createStatement() on con object?

Ami Ambre
Ranch Hand

Joined: Dec 26, 2007
Posts: 58
But Connection is a interface & so how can we access it

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

Connection con=DriverManager.getConnection("jdbcdbc:student");

Statement st = con.createStatement();
Creates a Statement object for sending SQL statements to the database
ReturnType of createStatement() is Statemen
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Originally posted by Ami Ambre:
But Connection is a interface & so how can we access it

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

Connection con=DriverManager.getConnection("jdbcdbc:student");

Statement st = con.createStatement();
Creates a Statement object for sending SQL statements to the database
ReturnType of createStatement() is Statemen


You (compiler) call (not exactly call, bind is more appropriate) method on reference and JVM calls method on object, the reference point to.

In other word, at compile time methods are bind with the reference and at run time methods are executed by object, the reference point to.

Now you figure out what's happening above.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Connection is a interface & so how can we access it createStatement() on con object?