Hi,
I have a doubt here, plz go thru the code snippet here:

Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from emp");

Statement and ResultSet are interfaces. executeQuery() method of Statement interface returns a ResultSet object here. That means defnitely Statement should implement ResultSet interface methods to return a ResultSet object, but Statement is an interface, it cldnt implement another interface. Can anyone please clarify this.....thanks

That means defnitely Statement should implement ResultSet interface methods to return a ResultSet object

No, Statement doesn't need to implement ResultSet:

public interface Resultset {
 // some methods
}


public class SomeResultSet implements ResultSet  {
   // someone has implemented all the methods of the ResultSet
}
public interface Statement {
  public Resultset executeQuery(String s);
}


public class SomeStatement implements Statement {
  public Resultset executeQuery(String s) {
      SomeResultSet srs = new SomeResultSet();
// code to create the Resultset
     return srs;
  }
}

In the same way someone has implemented the Connection interface, so when you call DriverManager to get the Connection the implemented class is returned instead, in which there is the implementation that returns the implemented Statement.
In other words, java has provided only the interfaces and it's up to the database "vendor" to provide the implemented classes.
When you downloaded the mysql java connector jar, what do you think there is inside it?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.