A hard Question about Java interfaces.!_NEWLINE_!Please Help.
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Vadim_Fain
Posted On:   Monday, June 17, 2002 02:02 AM

There is something strange I found about implementation of this interface. Here is my code that works OK: MyClass sc = new StormContext(); PreparedStatement ps1 = sc.getConnection().prepareStatement("SELECT * FROM MyTable WHERE Row1 = ? AND Row2 = ?"); ps1.setInt(1,100); ps1.setBoolean(2,false); ResultSet vrRs = ps1.executeQuery(); this is method getConnection of MyClass: public static Connection getSessionConnection() { myConnection = DriverManager.getConnection("jdbc:JTurbo://" + System.getProperty ("DBSessionsMachine") + "/" + System.getProperty("DBSessionsName") + "/sql70=true/sp=" + Sy   More>>

There is something strange I found about implementation of this interface.
Here is my code that works OK:

			

MyClass sc = new StormContext();
PreparedStatement ps1 = sc.getConnection().prepareStatement("SELECT * FROM MyTable WHERE Row1 = ? AND Row2 = ?");
ps1.setInt(1,100);
ps1.setBoolean(2,false);
ResultSet vrRs = ps1.executeQuery();

this is method getConnection of MyClass:
			
public static Connection getSessionConnection() {
myConnection = DriverManager.getConnection("jdbc:JTurbo://" + System.getProperty
("DBSessionsMachine") + "/" + System.getProperty("DBSessionsName") + "/sql70=true/sp=" + System.getProperty("PoolingPreparedStatement"), System.getProperty("DBUserName"),
System.getProperty("DBPassword"));

return myConnection;
}

How does it work if I never implemented PreparedStatement, Connection or Statement interfaces?
It looks like
PreparedStatement.executeQuery()
has a body!


The question is - where is the body of PreparedStatement.executeQuery() ?


Thanks in advance,
Vadim.    <<Less

Re: A hard Question about Java interfaces.!_NEWLINE_!Please Help.

Posted By:   Christopher_Koenigsberg  
Posted On:   Monday, June 17, 2002 06:34 AM

where is the body of PreparedStatement.executeQuery() ?


It is in a .class file inside the .jar file for the "JTurbo" JDBC driver.

Re: A hard Question about Java interfaces.!_NEWLINE_!Please Help.

Posted By:   Simon_Ablett  
Posted On:   Monday, June 17, 2002 04:25 AM

Java uses public interface and so the relationship between a child and its parent is that the child 'is an' instance of the parent. That is to say, wherever an reference to the parent is required it can be replaced by a reference to the child. Example, assume that class 'A' inherits from class 'B' and that I have a method 'M' requiring an instance of class 'B' to be passed to it. I can call this method and pass it an instance of 'A' instead; since 'A' is really an instance of 'B'. Does this make sense?

The call to 'Connection.preparedStatement' will actually be returning a reference to a child of PreparedStatement (i.e. a class that has implemented its interface). Because the inheritance relationshship is 'is a' however, you can refer to it as if it was an instance of the parent.

Regards.
About | Sitemap | Contact