GroupeZ Docs
Getting Started

Database Connections

Sarah supports multiple database systems through a unified interface. This guide covers how to configure and manage database connections.

Supported Databases

DatabaseConnection ClassConfiguration Method
MySQLMySqlConnectionDatabaseConfiguration.create()
MariaDBMariaDbConnectionDatabaseConfiguration.createMariaDb()
SQLiteSqliteConnectionDatabaseConfiguration.sqlite()

MySQL Connection

Basic Setup

DatabaseConfiguration config = DatabaseConfiguration.create(
    "username",     // Database user
    "password",     // Database password
    3306,           // Port
    "localhost",    // Host
    "my_database"   // Database name
);

DatabaseConnection connection = new MySqlConnection(config);
connection.connect();

With Debug Mode

Enable SQL query logging for debugging:

DatabaseConfiguration config = DatabaseConfiguration.create(
    "username",
    "password",
    3306,
    "localhost",
    "my_database",
    true  // Enable debug mode
);

MariaDB Connection

MariaDB configuration is similar to MySQL:

DatabaseConfiguration config = DatabaseConfiguration.createMariaDb(
    "username",
    "password",
    3306,
    "localhost",
    "my_database"
);

DatabaseConnection connection = new MariaDbConnection(config);
connection.connect();

Without Port (Default 3306)

DatabaseConfiguration config = DatabaseConfiguration.createMariaDb(
    "username",
    "password",
    "localhost",
    "my_database"
);

SQLite Connection

SQLite is perfect for development or small projects:

// Create configuration
DatabaseConfiguration config = DatabaseConfiguration.sqlite(true); // debug mode

// Create connection with folder path
// The database file will be created as "database.db" in this folder
DatabaseConnection connection = new SqliteConnection(config, myPluginFolder);
connection.connect();

Complete SQLite Example

public class MyPlugin extends JavaPlugin {

    private DatabaseConnection connection;

    @Override
    public void onEnable() {
        DatabaseConfiguration config = DatabaseConfiguration.sqlite(false);
        this.connection = new SqliteConnection(config, getDataFolder());

        try {
            connection.connect();
            getLogger().info("Connected to SQLite database!");
        } catch (SQLException e) {
            getLogger().severe("Failed to connect to SQLite!");
            e.printStackTrace();
        }
    }
}

DatabaseConfiguration Methods

Factory Methods

MethodDescription
create(user, password, port, host, database)Create MySQL config
create(user, password, port, host, database, debug)Create MySQL config with debug
createMariaDb(user, password, port, host, database)Create MariaDB config
createMariaDb(user, password, port, host, database, debug)Create MariaDB config with debug
sqlite(debug)Create SQLite config

Instance Methods

MethodReturn TypeDescription
getUser()StringGet database username
getPassword()StringGet database password
getPort()intGet database port
getHost()StringGet database host
getDatabase()StringGet database name
isDebug()booleanCheck if debug mode is enabled
getDatabaseType()DatabaseTypeGet the database type enum
replacePrefix(tableName)StringReplace table prefix
getMaximumPoolSize()IntegerGet the pool size, null for the default
getMinimumIdle()IntegerGet the minimum idle connections, null for the default
getMaxLifetime()LongGet the connection lifetime in milliseconds, null for the default (1.26+)

Connection Pool (HikariCP)

HikariDatabaseConnection opens a HikariCP pool for MySQL and MariaDB. Its settings are tuned on the DatabaseConfiguration, each with... method returns a new configuration:

DatabaseConfiguration config = DatabaseConfiguration.create("username", "password", 3306, "localhost", "my_database", false, DatabaseType.MYSQL)
        .withPoolSettings(10, 2)                         // maximum pool size, minimum idle
        .withMaxLifetime(TimeUnit.MINUTES.toMillis(10)); // since 1.26

DatabaseConnection connection = new HikariDatabaseConnection(config, logger);
MethodDescriptionDefault (null)
withPoolSettings(maximumPoolSize, minimumIdle)Pool size and idle connections kept opencores * 2 + 1, and min(pool size, 10)
withMaxLifetime(maxLifetime)Lifetime of a connection in milliseconds before it is retired. 0 keeps connections until the pool closes. HikariCP replaces values below 30 seconds with its default30 minutes

Set the max lifetime a few minutes below the database wait_timeout, or below the idle timeout of a proxy in front of it, so the pool never hands out a connection the server already closed.

Connection Lifecycle

Connecting

try {
    connection.connect();
} catch (SQLException e) {
    // Handle connection failure
    e.printStackTrace();
}

Disconnecting

Always disconnect when your plugin disables:

@Override
public void onDisable() {
    if (connection != null) {
        connection.disconnect();
    }
}

Getting Raw Connection

If you need the underlying JDBC connection:

Connection jdbcConnection = connection.getConnection();

Best Practices

1. Always Handle Exceptions

try {
    connection.connect();
} catch (SQLException e) {
    logger.severe("Database connection failed: " + e.getMessage());
    // Disable plugin or use fallback
}

2. Use SQLite for Development

boolean isDevelopment = true; // or from config

if (isDevelopment) {
    connection = new SqliteConnection(DatabaseConfiguration.sqlite(true), folder);
} else {
    connection = new MySqlConnection(productionConfig);
}

3. Close Connections Properly

@Override
public void onDisable() {
    // Save pending data first
    saveAllData();

    // Then disconnect
    if (connection != null) {
        connection.disconnect();
    }
}

Next Steps

On this page

GroupeZ MCP

Documentation in your AI

MCP lets your AI search GroupeZ documentation and read current examples to help you configure your plugins.

Read-only · No documentation API key needed

1. Copy the server URL

Transport: HTTP (Streamable HTTP). Authentication: none. Your tool uses its own model and subscription limits.

  1. Open Plugins in ChatGPT on the web, then + → Add custom MCP server.
  2. Name it ‘GroupeZ Documentation’, paste the URL above and choose ‘No authentication’. Create and install the plugin.
  3. In a conversation, type @ and select the plugin before asking. If needed, enable search, get_page and list_pages in its settings.
Official setup guide

3. Ask a question

Use GroupeZ MCP to help me create a zMenu inventory. Search relevant pages, read the examples and cite your sources.
Other clients and troubleshooting

For clients using mcpServers, adapt this example to their format:

{
  "mcpServers": {
    "groupez-docs": {
      "url": ""
    }
  }
}

Available tools are search, get_page and list_pages. Refresh the connector’s tools after updates. If your AI cannot access them, check that the connector is enabled in the conversation and your account allows custom MCP servers. Opening the URL in a browser is not an MCP test.