Hi, Is Statement object an interface or class? if its interface then all methods have to be implemented but we just cteate and start using its methods, if its a class then it has to be instantiated which we dont do. Then what exactly is a statement object and why?
One of the strengths of JDBC is that it is all based on interfaces. Interfaces allow you to define the behaviour of a class without defining the specifics of how thet behaviour is implemented. One of the only concrete classes you usually deal with in JDBC is the DriverManager, and everything after this in terms of interfaces. Note that a Connection is also an interface. When you call DriverManager.getConnection, it takes care of the object creation and passes a Class to you. Although it passes you a real class, you only know it behaves like a Connection. You are only interested in its Connection-like behaviour. It is possible to find out what the hidden class is, and it is even possible to cast to this hidden type, but this is almost always a bad idea. Now we have a class but we are not sure what the exact type is, but we know it behaves like a Connection. One of the behaviuours of a Connection is that using createStatement() will pass you something that behaves like a Statement. Again a Statement is an interface and all we know is that there is a concrete class hidden from us that behaves like a Statement, but all we care about is that it behaves like a Statement. Where did this statement come from? Although the Connection is an interface, in reality it is a hidden concrete class. When call createStatement on the interface, you are really calling createStatement on the class, and this class knows how to create the sort of Statement that it needs to execute statements. If you run Oracle, you get Oracle Connections and Statements, if you run MySQL, you get MySQL Connections and Statements. I hope this helps. Dave