database utility class
public class DBUtility {
private final static String url = ConfigReader.getProperty("JDBC_URL"),
private final static String username =ConfigReader.getProperty("JDBC_UserName"),
private final static String password = ConfigReader.getProperty("JDBC_PassWord");
private static Connection connection;
private static Statement statement;
public static DatabaseMetaData metadata;
static { ==> it is a good static block and try/catch example...
try {
connection = DriverManager.getConnection(url, username, password);
statement = connection.createStatement();
metadata = connection.getMetaData();
} catch(Exception e) {}
}
public static ResultSet getResult(String query) {
ResultSet result = null;
try {
result = statement.executeQuery(query);
} catch(Exception e) {}
return result;
}
public static void tearDown() {
try {
connection.close();
}catch(Exception e) { }
}