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 TypeMethodDescriptionbooleanChecks if a connection is open with the database.booleanCloses the connection with the database.Gets the connection with the database.Opens a connection with the database.Executes a SQL Query.intExecutes 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:
forceConnectionin classDatabase- Throws:
SQLException
-
openConnection
Description copied from class:DatabaseOpens a connection with the database.- Specified by:
openConnectionin classDatabase- Returns:
- Opened connection
- Throws:
SQLException- if the connection can not be opened
-
checkConnection
Description copied from class:DatabaseChecks if a connection is open with the database.- Specified by:
checkConnectionin classDatabase- Returns:
- true if the connection is open
- Throws:
SQLException- if the connection cannot be checked
-
getConnection
Description copied from class:DatabaseGets the connection with the database.- Specified by:
getConnectionin classDatabase- Returns:
- Connection with the database, null if none
-
closeConnection
Description copied from class:DatabaseCloses the connection with the database.- Specified by:
closeConnectionin classDatabase- Returns:
- true if successful
- Throws:
SQLException- if the connection cannot be closed
-
querySQL
Description copied from class:DatabaseExecutes a SQL Query. If the connection is closed, it will be opened.- Specified by:
querySQLin 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:DatabaseExecutes an Update SQL Query. SeeStatement.executeUpdate(String). If the connection is closed, it will be opened.- Specified by:
updateSQLin classDatabase- Parameters:
query- Query to be run- Returns:
- Result Code, see
Statement.executeUpdate(String) - Throws:
SQLException- If the query cannot be executed
-