在该方法中readAll()我得到了NullPointerException我Connection,但为什么,我怎么可能改变这种状况?
如果我用主类测试它一切正常,但如果我在服务器(网络服务器 - 本地)上做同样的事情,它会抛出一个NullPointerException.
这是我的ConnectionManager课:
public class ConnectionManager {
private volatile static ConnectionManager connectionManager = null;
private Connection connection = null;
private ConnectionManager() throws SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException {
DBProperties properties = DBProperties.getInstance();
String url = properties.getStringProperty("databaseURL") + properties.getStringProperty("pathToDB") + properties.getStringProperty("urlSettings");
String user = properties.getStringProperty("user");
String passwort = properties.getStringProperty("password");
try { // load driver
Class.forName(properties.getStringProperty("dbDriver")).newInstance();
connection = DriverManager.getConnection(url, user, passwort);
} catch (SQLException ex) {
Logger.getLogger(ConnectionManager.class.getName()).log(Level.SEVERE, null, ex);
}
}
public synchronized static ConnectionManager getInstance() throws SQLException {
if (connectionManager == null) {
try {
connectionManager = new ConnectionManager();
} catch (Exception ex) {
Logger.getLogger(ConnectionManager.class.getName()).log(Level.SEVERE, null, ex);
}
}
return connectionManager;
}
public Connection getConnection() {
return connection;
}
public static void closeConnection() {
//close the connection only if there is a instance
//--> closeConnection() can always be called.
//(e.g. if non JDBC-Dao's are used --> ConnectionManager is not instantiated)
if (connectionManager != null) {
try {
connectionManager.connection.close();
} catch (SQLExce
千巷猫影
相关分类