Class MySQLDatabase

java.lang.Object
me.despical.commons.database.MySQLDatabase

public class MySQLDatabase extends Object
Version:
1.0.0
Author:
Despical

Created at 30.05.2020

  • Constructor Details

    • MySQLDatabase

      public MySQLDatabase(org.bukkit.plugin.java.JavaPlugin plugin, String fileName)
      Initializes the database using a custom config file name within a plugin's folder.
      Parameters:
      plugin - The JavaPlugin instance.
      fileName - The name of the config file (e.g., "database").
    • MySQLDatabase

      public MySQLDatabase(org.bukkit.plugin.java.JavaPlugin plugin, org.bukkit.configuration.file.FileConfiguration config)
      Initializes the database using a plugin's FileConfiguration. Uses the plugin's built-in logger.
      Parameters:
      plugin - The JavaPlugin instance, used to get the logger.
      config - The FileConfiguration containing database credentials.
    • MySQLDatabase

      public MySQLDatabase(org.bukkit.configuration.file.FileConfiguration configuration)
    • MySQLDatabase

      public MySQLDatabase(org.bukkit.configuration.file.FileConfiguration configuration, String userPath, String passwordPath, String jdbcUrlPath)
    • MySQLDatabase

      public MySQLDatabase(String user, String password, String jdbcUrl)
      Initializes the database using a full JDBC URL. Uses a default standalone logger.
      Parameters:
      user - The database username.
      password - The database password.
      jdbcUrl - The full JDBC connection URL.
    • MySQLDatabase

      public MySQLDatabase(String user, String password, String host, String database, int port)
      Initializes the database using detailed connection properties. Uses a default standalone logger.
      Parameters:
      user - The database username.
      password - The database password.
      host - The database host address.
      database - The name of the database.
      port - The port number for the database.
  • Method Details

    • executeUpdate

      @Deprecated public void executeUpdate(String query)
      Deprecated.
      Use executePreparedUpdate(java.lang.String, java.lang.Object...) to prevent SQL injection vulnerabilities.
      WARNING: This method is NOT SAFE and is vulnerable to SQL INJECTION. Only use this for static queries that do not involve user input (e.g., CREATE TABLE).
      Parameters:
      query - The SQL query to execute.
    • executePreparedUpdate

      public void executePreparedUpdate(String query, Object... params)
      SECURE: Executes an update query using a PreparedStatement to prevent SQL injection. USE THIS METHOD for INSERT, UPDATE, or DELETE operations.
      Parameters:
      query - The SQL query to execute (e.g., "INSERT INTO players (uuid, name) VALUES (?, ?)")
      params - The parameters to be set for the '?' placeholders, in order.
    • shutdownConnPool

      public void shutdownConnPool()
      Safely shuts down the connection pool.
    • getConnection

      public Connection getConnection() throws SQLException
      Retrieves a database connection from the connection pool.
      Returns:
      A SQL Connection object.
      Throws:
      SQLException - If a connection cannot be obtained.
    • setLogger

      public void setLogger(Logger logger)
      Sets a new logger instance.
      Parameters:
      logger - The new logger to use.