DatabaseReporterpublic class DatabaseReporter extends Object This class will created a dummy database called testconnectivity.
and handshake with the database to get the Client Driver info. |
Fields Summary |
---|
private static final com.sun.enterprise.util.i18n.StringManager | lsm | private static final com.sun.enterprise.cli.framework.CLILogger | logger | private static final String | DERBY_CLIENT_DRIVER_CLASS_NAME | private static final String | URL | private static final String | DB_NAME | private static final String | USER | private static final String | PASS | private static final String | DB_PORT | private static final String | DB_HOME | private final String | dcn | private final String | url | private final String | user | private final String | password | private final String | dbhome | private final String | dbport | private final Connection | conn |
Constructors Summary |
---|
public DatabaseReporter(String dbhome, String dbport, String dcn, String url, String user, String password)
//constructor
this.dcn = dcn;
this.user = user;
this.password = password;
this.dbhome = dbhome;
this.dbport = dbport;
this.url = url+dbport+DB_NAME;
Class.forName(dcn);
conn = DriverManager.getConnection(this.url, this.user, this.password);
|
Methods Summary |
---|
private void | display()display the database info.
logger.printMessage(getDatabaseInfoMsg());
logger.printMessage(getDatabaseDriverNameMsg());
logger.printMessage(getDatabaseDriverVersionMsg());
logger.printMessage(getJDBCSpecificationMsg());
| private java.lang.String | getDatabaseDriverNameMsg()get database driver name.
final String sDriverName = conn.getMetaData().getDriverName();
return ( lsm.getString("database.driver.name.msg", sDriverName));
| private java.lang.String | getDatabaseDriverVersionMsg()get database driver version.
final String sDriverVersion = conn.getMetaData().getDriverVersion();
return ( lsm.getString("database.driver.version.msg", sDriverVersion));
| private java.lang.String | getDatabaseInfoMsg()get database info msg.
return (lsm.getString("database.info.msg"));
| private java.lang.String | getJDBCSpecificationMsg()get jdbc major and minor version.
final int iJDBCMajorVersion = conn.getMetaData().getJDBCMajorVersion();
final int iJDBCMinorVersion = conn.getMetaData().getJDBCMinorVersion();
final String sJDBCSpec = iJDBCMajorVersion + "." + iJDBCMinorVersion;
return ( lsm.getString("jdbc.version.msg", sJDBCSpec));
| public static void | main(java.lang.String[] args)
DatabaseReporter dmt = null;
if (args == null || (args.length < 6 && args.length>2) ) {
dmt = new DatabaseReporter(DB_HOME, DB_PORT, DERBY_CLIENT_DRIVER_CLASS_NAME, URL, USER, PASS);
}
else if (args.length == 2) {
dmt = new DatabaseReporter(args[0], args[1], DERBY_CLIENT_DRIVER_CLASS_NAME, URL, USER, PASS);
}
else {
dmt = new DatabaseReporter(args[0], args[1], args[2], args[3], args[4], args[5]);
}
try {
dmt.display();
dmt.removeDatabaseFile();
}
catch (Exception e) {
logger.printMessage(lsm.getString("UnableToConnectToDatabase"));
System.exit(1);
}
| private void | removeDatabaseFile()remove database file
File f = new File(dbhome, "testconnectivity");
FileUtils.whack(f);
|
|