Class SQLDatabase

java.lang.Object
studio.magemonkey.codex.mccore.sql.direct.SQLDatabase

public class SQLDatabase extends Object
Manager for connection to and interacting with a MySQL database
  • 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 reference
      host - host name
      port - port number
      database - database name
      username - username
      password - 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 reference
      config - configuration to loaf from
  • Method Details

    • getLogger

      public Logger getLogger()

      Gets the logger from the owning plugin.

      Returns:
      logger of the owning plugin
    • getMeta

      public DatabaseMetaData getMeta() throws SQLException

      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

      public PreparedStatement getStatement(String sql)

      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

      public Statement getStatement()

      Retrieves an empty statement from the connection to use.

      Returns:
      empty statement
    • tableExists

      public boolean tableExists(String name)
      Checks if a table with the name exists
      Parameters:
      name - table name
      Returns:
      true if exists, false otherwise
    • tableExists

      public boolean tableExists(org.bukkit.plugin.Plugin plugin, String name)
      Checks if a table with the name exists for a plugin
      Parameters:
      plugin - plugin to check for
      name - table name
      Returns:
      true if exists, false otherwise
    • createTable

      public SQLTable createTable(String name)

      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

      public SQLTable createTable(org.bukkit.plugin.Plugin plugin, String name)

      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 for
      name - name of the table
    • deleteTable

      public boolean deleteTable(String name)

      Deletes a table from the database.

      Parameters:
      name - name of the table to delete
      Returns:
      true if successful, false otherwise
    • deleteTable

      public boolean deleteTable(org.bukkit.plugin.Plugin plugin, String name)

      Deletes a table from the database for a plugin.

      Parameters:
      plugin - plugin to delete the table for
      name - name of the table to delete
      Returns:
      true if successful, false otherwise