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 boolean
Checks if a connection is open with the database.abstract boolean
Closes the connection with the database.abstract Connection
abstract Connection
Gets the connection with the database.abstract Connection
Opens a connection with the database.abstract ResultSet
Executes a SQL Query.abstract int
Executes an Update SQL Query.
-
Constructor Details
-
Database
public Database()
-
-
Method Details
-
forceConnection
- Throws:
SQLException
ClassNotFoundException
-
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()
-