Updated the constructor & the readme file
This commit is contained in:
parent
ca3e4d180c
commit
47c8a1391d
@ -32,18 +32,10 @@ This is a small project for quickly managing a MySQL database in Java. It makes
|
|||||||
```java
|
```java
|
||||||
MySQLConnection connection = new MySQLConnection(hostname, username, password, database).connect();
|
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
|
- Example of a constructor with optional login parameters
|
||||||
```java
|
```java
|
||||||
MySQLConnection connection = new MySQLConnection(hostname, username, password, database, LoginParam.AUTO_RECONNECT, LoginParam.NO_SSL).connect();
|
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
|
#### Login Parameters
|
||||||
- DEFAULT *(useSSL=false&autoReconnect=true&useUnicode=yes&characterEncoding=UTF-8&useTimezone=true&serverTimezone=UTC)*
|
- DEFAULT *(useSSL=false&autoReconnect=true&useUnicode=yes&characterEncoding=UTF-8&useTimezone=true&serverTimezone=UTC)*
|
||||||
- NO_SSL *(useSSL=false)*
|
- NO_SSL *(useSSL=false)*
|
||||||
|
@ -5,7 +5,6 @@ import de.gnmyt.SQLToolkit.manager.DataBaseSelection;
|
|||||||
import de.gnmyt.SQLToolkit.manager.InsertManager;
|
import de.gnmyt.SQLToolkit.manager.InsertManager;
|
||||||
import de.gnmyt.SQLToolkit.manager.ResultManager;
|
import de.gnmyt.SQLToolkit.manager.ResultManager;
|
||||||
import de.gnmyt.SQLToolkit.manager.UpdateManager;
|
import de.gnmyt.SQLToolkit.manager.UpdateManager;
|
||||||
import de.gnmyt.SQLToolkit.types.LogLevelType;
|
|
||||||
import de.gnmyt.SQLToolkit.types.LoginParam;
|
import de.gnmyt.SQLToolkit.types.LoginParam;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -30,84 +29,21 @@ public class MySQLConnection {
|
|||||||
private Connection con;
|
private Connection con;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the Connection String
|
* Basic constructor for the connection
|
||||||
* @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
|
|
||||||
* @param hostname MySQL server hostname
|
* @param hostname MySQL server hostname
|
||||||
* @param username MySQL server username
|
* @param username MySQL server username
|
||||||
* @param password MySQL server password
|
* @param password MySQL server password
|
||||||
* @param database MySQL server database
|
* @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.hostname = hostname;
|
||||||
this.username = username;
|
this.username = username;
|
||||||
this.password = password;
|
this.password = password;
|
||||||
this.database = database;
|
this.database = database;
|
||||||
updateConnectString(loginParams);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Basic constructor for the Connection
|
* Advanced constructor for the connection
|
||||||
* @param hostname MySQL server hostname
|
* @param hostname MySQL server hostname
|
||||||
* @param username MySQL server username
|
* @param username MySQL server username
|
||||||
* @param password MySQL server password
|
* @param password MySQL server password
|
||||||
@ -119,7 +55,7 @@ public class MySQLConnection {
|
|||||||
this.username = username;
|
this.username = username;
|
||||||
this.password = password;
|
this.password = password;
|
||||||
this.database = database;
|
this.database = database;
|
||||||
updateConnectString(loginParams);
|
updateConnectionString(loginParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -268,4 +204,65 @@ public class MySQLConnection {
|
|||||||
return this;
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user