Hallo, ich habe eine Klasse Database, die mir eine Verbindung zu einer db herstellt:
(der Einfachkeit halber bild ich sie hier nicht vollständig ab)
also, Schema ist bekannt, oder?!
hier habe ich ein Klasse, die von Database erbt:
... soweit auch klar, oder?!
jetzt kommt noch eine Klasse, die in meinen Augen gleich aufgebaut ist:
der kleine Unterschied: die Klasse SAG-Database funktioniert; die Klasse CdbDatabase gibt einen Fehler:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The return type is incompatible with Database.getInstance()
wie kann das sein?!
mfg, guni
(der Einfachkeit halber bild ich sie hier nicht vollständig ab)
Java:
public class Database {
private static Database INSTANCE;
public Connection sql;
public Statement stmnt;
public static Database getInstance() throws Exception {
if (INSTANCE == null) {
INSTANCE = new Database();
}
return INSTANCE;
}
protected Database() throws ClassNotFoundException, SQLException {
Class.forName("oracle.jdbc.driver.OracleDriver");
sql = DriverManager.getConnection(dbconnect, user, password);
stmnt = sql.createStatement();
}
}
also, Schema ist bekannt, oder?!
hier habe ich ein Klasse, die von Database erbt:
Java:
public class SagDatabase extends Database {
private static SagDatabase INSTANCE;
public static SagDatabase getInstance() throws Exception {
if (INSTANCE == null) {
INSTANCE = new SagDatabase();
}
return INSTANCE;
}
private SagDatabase() throws Exception {
super();
}
}
jetzt kommt noch eine Klasse, die in meinen Augen gleich aufgebaut ist:
Java:
public class CdbDatabase extends Database {
private static CdbDatabase INSTANCE;
public static CdbDatabase getInstance() throws Exception {
if (INSTANCE == null) {
INSTANCE = new CdbDatabase();
}
return INSTANCE;
}
private CdbDatabase() throws Exception {
super();
}
}
der kleine Unterschied: die Klasse SAG-Database funktioniert; die Klasse CdbDatabase gibt einen Fehler:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The return type is incompatible with Database.getInstance()
wie kann das sein?!
mfg, guni