diff --git a/README.md b/README.md index b915628..0d49a82 100644 --- a/README.md +++ b/README.md @@ -32,18 +32,10 @@ This is a small project for quickly managing a MySQL database in Java. It makes ```java MySQLConnection connection = new MySQLConnection(hostname, username, password, database).connect(); ``` - - Example of a constructor with setting the logging level - ```java - MySQLConnection connection = new MySQLConnection(hostname, username, password, database, LogLevelType.ALL).connect(); - ``` - Example of a constructor with optional login parameters ```java MySQLConnection connection = new MySQLConnection(hostname, username, password, database, LoginParam.AUTO_RECONNECT, LoginParam.NO_SSL).connect(); ``` - #### Logging Levels - - NONE - Sends nothing - - LOW - Sends Warnings & Errors - - ALL - Sends Infos, Warnings & Errors #### Login Parameters - DEFAULT *(useSSL=false&autoReconnect=true&useUnicode=yes&characterEncoding=UTF-8&useTimezone=true&serverTimezone=UTC)* - NO_SSL *(useSSL=false)* diff --git a/src/main/java/de/gnmyt/SQLToolkit/drivers/MySQLConnection.java b/src/main/java/de/gnmyt/SQLToolkit/drivers/MySQLConnection.java index 8c0dcd8..86b297c 100755 --- a/src/main/java/de/gnmyt/SQLToolkit/drivers/MySQLConnection.java +++ b/src/main/java/de/gnmyt/SQLToolkit/drivers/MySQLConnection.java @@ -5,7 +5,6 @@ import de.gnmyt.SQLToolkit.manager.DataBaseSelection; import de.gnmyt.SQLToolkit.manager.InsertManager; import de.gnmyt.SQLToolkit.manager.ResultManager; import de.gnmyt.SQLToolkit.manager.UpdateManager; -import de.gnmyt.SQLToolkit.types.LogLevelType; import de.gnmyt.SQLToolkit.types.LoginParam; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -30,84 +29,21 @@ public class MySQLConnection { private Connection con; /** - * Update the Connection String - * @param loginParams New login parameters - * @return this class - */ - public MySQLConnection updateConnectString(LoginParam... loginParams) { - this.connectString = getConnectionString(loginParams); - return this; - } - - /** - * Set the Connection String - * @param tablePrefixVariable New table prefix variable - * @return this class - */ - public MySQLConnection setTablePrefixVariable(String tablePrefixVariable) { - this.tablePrefixVariable = tablePrefixVariable; - return this; - } - - /** - * Set the current table Prefix - * @param tablePrefix New table prefix - * @return this class - */ - public MySQLConnection setTablePrefix(String tablePrefix) { - this.tablePrefix = tablePrefix; - return this; - } - - /** - * Get the current table Prefix - * @return the prefix - */ - public String getTablePrefix() { - return tablePrefix; - } - - /** - * Get the current jdbc connection string for mysql - * @param loginParams login parameters - * @return the string - */ - private String getConnectionString(LoginParam[] loginParams) { - boolean used = false;StringBuilder currentString = new StringBuilder(); - for (LoginParam param : loginParams) { - String currentChar = (used) ? "&" : "?";used = true; - currentString.append(currentChar).append(param.getValue()); - } - return currentString.toString(); - } - - /** - * Check if you are connected - * @return status of the connection - */ - public boolean isConnected() { - return (con != null); - } - - /** - * Basic constructor for the Connection + * Basic constructor for the connection * @param hostname MySQL server hostname * @param username MySQL server username * @param password MySQL server password * @param database MySQL server database - * @param logLevel Logging level - * @param loginParams Login parameters */ - public MySQLConnection(String hostname, String username, String password, String database, LogLevelType logLevel, LoginParam... loginParams) { + public MySQLConnection(String hostname, String username, String password, String database) { this.hostname = hostname; this.username = username; this.password = password; this.database = database; - updateConnectString(loginParams); } /** - * Basic constructor for the Connection + * Advanced constructor for the connection * @param hostname MySQL server hostname * @param username MySQL server username * @param password MySQL server password @@ -119,7 +55,7 @@ public class MySQLConnection { this.username = username; this.password = password; this.database = database; - updateConnectString(loginParams); + updateConnectionString(loginParams); } /** @@ -268,4 +204,65 @@ public class MySQLConnection { return this; } + /** + * Update the Connection String + * @param loginParams New login parameters + * @return this class + */ + public MySQLConnection updateConnectionString(LoginParam... loginParams) { + this.connectString = getConnectionString(loginParams); + return this; + } + + /** + * Set the Connection String + * @param tablePrefixVariable New table prefix variable + * @return this class + */ + public MySQLConnection setTablePrefixVariable(String tablePrefixVariable) { + this.tablePrefixVariable = tablePrefixVariable; + return this; + } + + /** + * Set the current table Prefix + * @param tablePrefix New table prefix + * @return this class + */ + public MySQLConnection setTablePrefix(String tablePrefix) { + this.tablePrefix = tablePrefix; + return this; + } + + /** + * Get the current table Prefix + * @return the prefix + */ + public String getTablePrefix() { + return tablePrefix; + } + + /** + * Get the current jdbc connection string for mysql + * @param loginParams login parameters + * @return the string + */ + private String getConnectionString(LoginParam[] loginParams) { + boolean used = false;StringBuilder currentString = new StringBuilder(); + for (LoginParam param : loginParams) { + String currentChar = (used) ? "&" : "?";used = true; + currentString.append(currentChar).append(param.getValue()); + } + return currentString.toString(); + } + + /** + * Check if you are connected + * @return status of the connection + */ + public boolean isConnected() { + return (con != null); + } + + }