// Make a Connection and create Statement and DatabaseMetaData objects
public void getDatabaseInformation(
String fileName){
try {
con = getConnection(fileName);
stmt = con.createStatement();
md = con.getMetaData();
}
catch(SQLException e) {
while(e != null) {
System.out.println("Error closing connection in tab switch");
System.out.println("SQLState: " + e.getSQLState());
System.out.println("Message: " + e.getMessage());
System.out.println("Vendor Code: " + e.getErrorCode());
e = e.getNextException();
System.out.println("");
}
}
catch(IOException e) {
System.out.println("Error in I/O operation: " + e);
}
}
// Makes the connection to the database
public static Connection getConnection(String fileName) throws SQLException, IOException {
Properties props = new Properties();
FileInputStream in = new FileInputStream(fileName);
props.load(in);
// force the driver to load with Class.forName()
try {
Class.forName(props.getProperty("jdbc.drivers"));
}
catch(ClassNotFoundException e){
System.out.println("Exception loading driver: " + e);
}
String url = props.getProperty("jdbc.url");
String username = props.getProperty("jdbc.username");
String password = props.getProperty("jdbc.password");
return DriverManager.getConnection(url);
}