]> git.mxchange.org Git - addressbook-swing.git/commitdiff
Fixed and added more MySQL-related stuff
authorRoland Haeder <roland@mxchange.org>
Wed, 29 Jul 2015 12:51:21 +0000 (14:51 +0200)
committerRoland Haeder <roland@mxchange.org>
Wed, 29 Jul 2015 12:51:21 +0000 (14:51 +0200)
Signed-off-by:Roland Häder <roland@mxchange.org>

Addressbook/src/org/mxchange/addressbook/BaseFrameworkSystem.java
Addressbook/src/org/mxchange/addressbook/database/backend/mysql/MySqlDatabaseBackend.java

index f5e8f053d8744401fc6647c3522d853c41be7c3d..50991963a6307e8404852849f0d054b960cfb5a5 100644 (file)
@@ -22,6 +22,7 @@ import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.io.PrintWriter;
+import java.text.MessageFormat;
 import java.util.Properties;
 import java.util.ResourceBundle;
 import org.apache.logging.log4j.LogManager;
@@ -125,10 +126,19 @@ public class BaseFrameworkSystem implements FrameworkInterface {
         * Prepares all properties, the file is written if it is not found
         */
        private void initProperties () {
+               // Trace message
+               this.getLogger().trace("CALLED!"); //NOI18N
+
                try {
                        // Try to read it
                        this.properties.load(new BufferedReader(new InputStreamReader(new FileInputStream(FrameworkInterface.PROPERTIES_CONFIG_FILE))));
+
+                       // Debug message
+                       this.getLogger().debug(MessageFormat.format("{0} properties has been loaded.", this.properties.size())); //NOI18N
                } catch (final FileNotFoundException ex) {
+                       // Debug message
+                       this.getLogger().debug(MessageFormat.format("Properties file {0} not found: {1}", FrameworkInterface.PROPERTIES_CONFIG_FILE, ex)); //NOI18N
+
                        /*
                         * The file is not found which is normal for first run, so
                         * initialize default values.
@@ -141,32 +151,48 @@ public class BaseFrameworkSystem implements FrameworkInterface {
                        // Something else didn't work
                        this.abortProgramWithException(ex);
                }
+
+               // Trace message
+               this.getLogger().trace("EXIT!"); //NOI18N
        }
 
        /**
         * Initializes properties with default values
         */
        private void initPropertiesWithDefault () {
+               // Trace message
+               this.getLogger().trace("CALLED!"); //NOI18N
+
                // Init default values:
                // Default database backend
-               this.properties.put("org.mxchange.addressbook.database.backendType", "base64csv");
+               this.properties.put("org.mxchange.addressbook.database.backendType", "base64csv"); //NOI18N
 
                // For MySQL backend
-               this.properties.put("org.mxchange.addressbook.database.mysql.host", "localhost");
-               this.properties.put("org.mxchange.addressbook.database.mysql.login", "");
-               this.properties.put("org.mxchange.addressbook.database.mysql.password", "");
+               this.properties.put("org.mxchange.addressbook.database.mysql.host", "localhost"); //NOI18N
+               this.properties.put("org.mxchange.addressbook.database.mysql.dbname", "test"); //NOI18N
+               this.properties.put("org.mxchange.addressbook.database.mysql.login", ""); //NOI18N
+               this.properties.put("org.mxchange.addressbook.database.mysql.password", ""); //NOI18N
+
+               // Trace message
+               this.getLogger().trace("EXIT!"); //NOI18N
        }
 
        /**
         * Writes the properties file to disk
         */
        private void writePropertiesFile () {
+               // Trace message
+               this.getLogger().trace("CALLED!"); //NOI18N
+
                try {
                        // Write it
-                       this.properties.store(new PrintWriter(FrameworkInterface.PROPERTIES_CONFIG_FILE), "This file is automatically generated. You may wish to alter it.");
+                       this.properties.store(new PrintWriter(FrameworkInterface.PROPERTIES_CONFIG_FILE), "This file is automatically generated. You may wish to alter it."); //NOI18N
                } catch (final IOException ex) {
                        this.abortProgramWithException(ex);
                }
+
+               // Trace message
+               this.getLogger().trace("EXIT!"); //NOI18N
        }
 
        /**
index f2fea93ce7fd64825747c11bb3d03190c69f37b0..6a7b0094f60a3672f34b3a140ed6b9e767b2161c 100644 (file)
@@ -20,6 +20,7 @@ import java.io.IOException;
 import java.sql.Connection;
 import java.sql.DriverManager;
 import java.sql.SQLException;
+import java.text.MessageFormat;
 import java.util.Iterator;
 import org.mxchange.addressbook.contact.Contact;
 import org.mxchange.addressbook.database.backend.BaseDatabaseBackend;
@@ -49,16 +50,26 @@ public class MySqlDatabaseBackend extends BaseDatabaseBackend implements Databas
                // Validate driver
                this.validateDriver("mysql"); //NOI18N
 
-               // Now that the driver is there ...
+               // Now that the driver is there, set the table name
+               this.setTableName(tableName);
        }
 
        @Override
        public void connectToDatabase () throws SQLException {
+               // Trace message
+               this.getLogger().trace("CALLED!");
+
                // Generate connection string
-               String connect = "jdbc:mysql://" + this.getProperty("org.mxchange.database.mysql.host") + "/" + this.getTableName();
+               String connect = String.format("jdbc:mysql://%s/%s", this.getProperty("org.mxchange.addressbook.database.mysql.host"), this.getProperty("org.mxchange.addressbook.database.mysql.dbname"));
+
+               // Debug message
+               this.getLogger().debug(MessageFormat.format("Attempting to connect to {0} ...", connect));
 
                // Now get a connection instance back
-               this.connection = DriverManager.getConnection(connect, this.getProperty("org.mxchange.database.mysql.login"), this.getProperty("org.mxchange.database.mysql.password"));
+               this.connection = DriverManager.getConnection(connect, this.getProperty("org.mxchange.addressbook.database.mysql.login"), this.getProperty("org.mxchange.addressbook.database.mysql.password"));
+
+               // Trace message
+               this.getLogger().trace("EXIT!");
        }
 
        @Override