Tuesday, 6 August 2013

different way for private abstract constructor in java?

different way for private abstract constructor in java?

I had a class for a db connection like that (simplified):
public class SQL {
private static SQL instance = null;
private static String ADRESS;
private SQL() {
try {
// Settings
settings = Settings.getInstance();
ADDRESS = settings.getAdress;
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://" + ADRESS + "...");
}
catch (SQLException e) {
throw e;
}
}
public static SQL getInstance() {
if(instance == null) {
instance = new SQL();
}
return instance;
}
public String select(...) {
// SELECT Code
}
public String update(...) {
// UPDATE Code
}
public String insert(...) {
// INSERT Code
}
}
But now I need two variants of SQL and they mainly differ only in the
settings (different databases). So I wanted to make SQL to an abstract
class and overwrite only the constructor in the two inherited classes. But
as far as I could find out it's not possible to have an abstract private
constructor!? So how can I change the class SQL to an abstract class then?
Thanks, I hope someone understands the problen :)

No comments:

Post a Comment