I'm trying to create a method that allows me to connect to a database. Since it can be use more than one different database I was trying to create a generic method that receives the database connection as String and connect to that database.
public static Connection ConnectingDB(String urlConnection) throws SQLException {
Connection c = null;
try {
Class.forName("??");
c = DriverManager.getConnection("??:"+ urlConnection);
} catch (Exception e) {
System.err.println(e.getClass().getName() + ": " + e.getMessage());
System.exit(0);
}
System.out.println("Opened database successfully");
return c;
}
What should I put in Class.forname
and in DriverManager.getConnection()
?