Package com.plotsquared.core.database
Class MySQL
java.lang.Object
com.plotsquared.core.database.Database
com.plotsquared.core.database.MySQL
Connects to and uses a MySQL database
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
Checks if a connection is open with the database.boolean
Closes the connection with the database.Gets the connection with the database.Opens a connection with the database.Executes a SQL Query.int
Executes an Update SQL Query.
-
Constructor Details
-
MySQL
Creates a new MySQL instance.- Parameters:
hostname
- Name of the hostport
- Port numberdatabase
- Database nameusername
- Usernamepassword
- Password
-
-
Method Details
-
forceConnection
- Specified by:
forceConnection
in classDatabase
- Throws:
SQLException
-
openConnection
Description copied from class:Database
Opens a connection with the database.- Specified by:
openConnection
in classDatabase
- Returns:
- Opened connection
- Throws:
SQLException
- if the connection can not be opened
-
checkConnection
Description copied from class:Database
Checks if a connection is open with the database.- Specified by:
checkConnection
in classDatabase
- Returns:
true
if the connection is open- Throws:
SQLException
- if the connection cannot be checked
-
getConnection
Description copied from class:Database
Gets the connection with the database.- Specified by:
getConnection
in classDatabase
- Returns:
- Connection with the database, null if none
-
closeConnection
Description copied from class:Database
Closes the connection with the database.- Specified by:
closeConnection
in classDatabase
- Returns:
true
if successful- Throws:
SQLException
- if the connection cannot be closed
-
querySQL
Description copied from class:Database
Executes a SQL Query. If the connection is closed, it will be opened.- Specified by:
querySQL
in classDatabase
- Parameters:
query
- Query to be run- Returns:
- the results of the query
- Throws:
SQLException
- If the query cannot be executed
-
updateSQL
Description copied from class:Database
Executes an Update SQL Query. SeeStatement.executeUpdate(String)
. If the connection is closed, it will be opened.- Specified by:
updateSQL
in classDatabase
- Parameters:
query
- Query to be run- Returns:
- Result Code, see
Statement.executeUpdate(String)
- Throws:
SQLException
- If the query cannot be executed
-