Class SQLDatabase
java.lang.Object
studio.magemonkey.codex.mccore.sql.direct.SQLDatabase
Manager for connection to and interacting with a MySQL database
-
Constructor Summary
ConstructorsConstructorDescriptionSQLDatabase(org.bukkit.plugin.Plugin plugin, String host, String port, String database, String username, String password) Initializes the data to connect to a MySQL databaseSQLDatabase(org.bukkit.plugin.Plugin plugin, org.bukkit.configuration.ConfigurationSection config) Loads SQL database data from the configuration section. -
Method Summary
Modifier and TypeMethodDescriptionvoidCloses the connection to the databasecreateTable(String name) Creates a new table in the database.createTable(org.bukkit.plugin.Plugin plugin, String name) Creates a new table in the database for a specific plugin.booleandeleteTable(String name) Deletes a table from the database.booleandeleteTable(org.bukkit.plugin.Plugin plugin, String name) Deletes a table from the database for a plugin.Gets the logger from the owning plugin.getMeta()Retrieves the metadata of the connection.Retrieves an empty statement from the connection to use.getStatement(String sql) Prepares a statement for the connection.booleanChecks whether or not the MySQL setup is connected.booleanOpens a connection to the serverbooleantableExists(String name) Checks if a table with the name existsbooleantableExists(org.bukkit.plugin.Plugin plugin, String name) Checks if a table with the name exists for a plugin
-
Constructor Details
-
SQLDatabase
public SQLDatabase(org.bukkit.plugin.Plugin plugin, String host, String port, String database, String username, String password) Initializes the data to connect to a MySQL database- Parameters:
plugin- plugin referencehost- host nameport- port numberdatabase- database nameusername- usernamepassword- password
-
SQLDatabase
public SQLDatabase(org.bukkit.plugin.Plugin plugin, org.bukkit.configuration.ConfigurationSection config) Loads SQL database data from the configuration section.
The format must be the following (not necessarily in the same order) for it to be recognized:
host: example port: 12345 databse: someDatabase username: myUser password: myPassword- Parameters:
plugin- plugin referenceconfig- configuration to loaf from
-
-
Method Details
-
getLogger
Gets the logger from the owning plugin.
- Returns:
- logger of the owning plugin
-
getMeta
Retrieves the metadata of the connection.
- Returns:
- metadata of the active connection
- Throws:
SQLException
-
isConnected
public boolean isConnected()Checks whether or not the MySQL setup is connected.
- Returns:
- true if connected, false otherwise
-
openConnection
public boolean openConnection()Opens a connection to the server- Returns:
- true if connected successfully, false otherwise
-
closeConnection
public void closeConnection()Closes the connection to the database -
getStatement
Prepares a statement for the connection.
- Parameters:
sql- SQL for the statement- Returns:
- prepared statement or null if not connected or failed to prepare it
-
getStatement
Retrieves an empty statement from the connection to use.
- Returns:
- empty statement
-
tableExists
Checks if a table with the name exists- Parameters:
name- table name- Returns:
- true if exists, false otherwise
-
tableExists
Checks if a table with the name exists for a plugin- Parameters:
plugin- plugin to check forname- table name- Returns:
- true if exists, false otherwise
-
createTable
Creates a new table in the database.
If the table already exists, that table will be returned instead.
- Parameters:
name- name of the table
-
createTable
Creates a new table in the database for a specific plugin.
If the table already exists, that table will be returned instead.
- Parameters:
plugin- plugin to create it forname- name of the table
-
deleteTable
Deletes a table from the database.
- Parameters:
name- name of the table to delete- Returns:
- true if successful, false otherwise
-
deleteTable
Deletes a table from the database for a plugin.
- Parameters:
plugin- plugin to delete the table forname- name of the table to delete- Returns:
- true if successful, false otherwise
-