Now consider the corresponding initialize method in the Statement class: public void initialize( SimpleTextConnection con) throws SQLException { // Save the owning connection object ownerConnection = con; } Which module will you compile first? You can t compile the Connection class until the Statement class has been compiled, and you can t compile the Statement class until the Connection class has been compiled. This is a circular dependency. Of course, the Java compiler does allow multiple files to be compiled at once, but some build environments do not support circular dependency. I have solved this problem in the SimpleText driver by defining some simple interface classes. In this way, the Statement class knows only about the general interface of the Connection class; the implementation of the interface does not need to be present. Our modified initialize method looks like this: public void initialize( SimpleTextIConnection con) throws SQLException { // Save the owning connection object ownerConnection = con; } Note that the only difference is the introduction of a new class, SimpleTextIConnection, which replaces SimpleTextConnection. I have chosen to preface the JDBC class name with an I to signify an interface. Here s the interface class: public interface SimpleTextIConnection extends java.sql.Connection { String[] parseSQL(String sql); Hashtable getTables(String directory, String table); Hashtable getColumns(String directory, String table); String getDirectory(String directory); } Note that our interface class extends the JDBC class, and our Connection class implements this new interface. This allows us to compile the interface first, then the Statement, followed by the Connection. Say good-bye to your circular dependency woes. Now, back to the Statement objects. The prepareStatement and prepareCall methods of the Connection object both require an SQL statement to be provided. This SQL statement should be pre-compiled and stored with the Statement object. If any errors are present in the SQL statement, an exception should be raised, and the Statement object should not be created. Tell Me About Yourself One of the most powerful aspects of the JDBC specification (which was inherited from X/Open) is the ability for introspection. This is the process of asking a driver for
Have all the commercials and ads about web hosting companies given you headache? Relax now.Our recommendation is web hosting comparisons.