/**
* An instance of a datbase connection
*/
- private Connection connection;
+ private static Connection connection;
/**
* Constructor with table name
// Trace message
this.getLogger().trace("CALLED!"); //NOI18N
+ // Is the connection already there?
+ if (MySqlDatabaseBackend.connection instanceof Connection) {
+ // Already connected
+ this.getLogger().debug("Connection is already established."); //NOI18N
+
+ // No need to connect
+ return;
+ }
+
// Generate connection string
String connect = String.format("jdbc:mysql://%s/%s", //NOI18N
this.getProperty("org.mxchange.addressbook.database.mysql.host"), //NOI18N
this.getLogger().debug(MessageFormat.format("Attempting to connect to {0} ...", connect)); //NOI18N
// Now get a connection instance back
- this.connection = DriverManager.getConnection(
+ MySqlDatabaseBackend.connection = DriverManager.getConnection(
connect,
this.getProperty("org.mxchange.addressbook.database.mysql.login"), //NOI18N
this.getProperty("org.mxchange.addressbook.database.mysql.password") //NOI18N
@Override
public void doShutdown () {
// This should not happen:
- assert(this.connection == null) : "connection is null";
+ assert(MySqlDatabaseBackend.connection == null) : "connection is null"; //NOI18N
try {
// Close down database connection
- this.connection.close();
+ MySqlDatabaseBackend.connection.close();
} catch (final SQLException ex) {
this.abortProgramWithException(ex);
}