Java Reference
In-Depth Information
Example 17−3: MakeAPIDB.java (continued)
// that indicates whether the class member is a field or a method.
Statement s = c.createStatement();
s.executeUpdate("CREATE TABLE package " +
"(id INT, name VARCHAR(80))");
s.executeUpdate("CREATE TABLE class " +
"(id INT, packageId INT, name VARCHAR(48))");
s.executeUpdate("CREATE TABLE member " +
"(classId INT, name VARCHAR(48), isField BIT)");
// Prepare some statements that will be used to insert records into
// these three tables.
insertpackage =
c.prepareStatement("INSERT INTO package VALUES(?,?)");
insertclass =
c.prepareStatement("INSERT INTO class VALUES(?,?,?)");
insertmember =
c.prepareStatement("INSERT INTO member VALUES(?,?,?)");
// Now loop through the list of classes and use reflection
// to store them all in the tables
int numclasses = classnames.size();
for(int i = 0; i < numclasses; i++) {
try {
storeClass((String)classnames.get(i));
}
catch(ClassNotFoundException e) {
System.out.println("WARNING: class not found: " +
classnames.get(i) + "; SKIPPING");
}
}
}
catch (Exception e) {
System.err.println(e);
if (e instanceof SQLException)
System.err.println("SQLState: " +
((SQLException)e).getSQLState());
System.err.println("Usage: java MakeAPIDB " +
"<classlistfile> <propfile>");
}
// When we're done, close the connection to the database
finally { try { c.close(); } catch (Exception e) {} }
}
/**
* This hash table records the mapping between package names and package
* id. This is the only one we need to store temporarily. The others are
* stored in the db and don't have to be looked up by this program
**/
static Map package_to_id = new HashMap();
// Counters for the package and class identifier columns
static int packageId = 0, classId = 0;
// Some prepared SQL statements for use in inserting
// new values into the tables. Initialized in main() above.
static PreparedStatement insertpackage, insertclass, insertmember;
/**
Search WWH ::




Custom Search