Java Reference
In-Depth Information
}
}
conExists = true ;
}
public abstract void doInsert();
public abstract void doUpdate();
public abstract void doDelete();
abstract String createValuesClause();
abstract String createSetClause();
abstract String createWhereClause();
abstract void getFieldsFromRS();
abstract void doSelect(String string);
abstract void doUpdate(String string);
}
Notice that before creating a connection object the init method checks to see if a connection object already exists.
This will cut down on the overhead of creating and maintaining multiple connections. Of course, each individual
“table class” will have to invoke the init method to ensure that the connection is created at least once.
Notice also that the init method uses a Properties object. Instead of dealing with all the individual property
variables, a Properties object is defined to hold many of the values and then passed to the DriverManager . Lastly,
note all the abstract methods. The various “table” subclasses of DB will be required to define these methods.
We need the “database classes” AccessDB, DB2DB, and OracleDB. As mentioned, each will contain the
information unique to that DBMS. The source code for each is:
package c10;
abstract class AccessDB extends DB{
public AccessDB () {
driver = "sun.jdbc.odbc.JdbcOdbcDriver";
url = "jdbc:odbc:TNT Database";
user = "anonymous";
pw = "guest";
}
}
package c10;
abstract class DB2DB extends DB{
public DB2DB () {
driver = "com.ibm.as400.access.AS400JDBCDriver";
url = "jdbc:as400:111.22.333.444";
user = "bjanson";
pw = "jeter";
}
}
package c10;
abstract class OracleDB extends DB {
public OracleDB () {
driver = "oracle.jdbc.driver.OracleDriver";
url = "jdbc:oracle:thin:@111.22.333.444:1521:SID";
user = "bjanson";
pw = "jeter";
}
}
 
Search WWH ::




Custom Search