Package com.plotsquared.core.database
Class Database
java.lang.Object
com.plotsquared.core.database.Database
Abstract Database class, serves as a base for any connection method (MySQL, SQLite, etc.)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract booleanChecks if a connection is open with the database.abstract booleanCloses the connection with the database.abstract Connectionabstract ConnectionGets the connection with the database.abstract ConnectionOpens a connection with the database.abstract ResultSetExecutes a SQL Query.abstract intExecutes an Update SQL Query.
-
Constructor Details
-
Database
public Database()
-
-
Method Details
-
forceConnection
- Throws:
SQLExceptionClassNotFoundException
-
openConnection
Opens a connection with the database.- Returns:
- Opened connection
- Throws:
SQLException- if the connection can not be openedClassNotFoundException- if the driver cannot be found
-
checkConnection
Checks if a connection is open with the database.- Returns:
- true if the connection is open
- Throws:
SQLException- if the connection cannot be checked
-
getConnection
Gets the connection with the database.- Returns:
- Connection with the database, null if none
-
closeConnection
Closes the connection with the database.- Returns:
- true if successful
- Throws:
SQLException- if the connection cannot be closed
-
querySQL
Executes a SQL Query. If the connection is closed, it will be opened.- Parameters:
query- Query to be run- Returns:
- the results of the query
- Throws:
SQLException- If the query cannot be executedClassNotFoundException- If the driver cannot be found; seeopenConnection()
-
updateSQL
Executes an Update SQL Query. SeeStatement.executeUpdate(String). If the connection is closed, it will be opened.- Parameters:
query- Query to be run- Returns:
- Result Code, see
Statement.executeUpdate(String) - Throws:
SQLException- If the query cannot be executedClassNotFoundException- If the driver cannot be found; seeopenConnection()
-