# mariadb > Configures MariaDB connections, schema management, and game state queries for L2J server. Use when: Setting up database connections, writing SQL queries, managing player/game data persistence, or troubleshooting database issues. - Author: valeriybaranyshyn-pixel - Repository: valeriybaranyshyn-pixel/Tales-of-Aden - Version: 20260202145225 - Stars: 0 - Forks: 0 - Last Updated: 2026-02-06 - Source: https://github.com/valeriybaranyshyn-pixel/Tales-of-Aden - Web: https://mule.run/skillshub/@@valeriybaranyshyn-pixel/Tales-of-Aden~mariadb:20260202145225 --- --- name: mariadb description: | Configures MariaDB connections, schema management, and game state queries for L2J server. Use when: Setting up database connections, writing SQL queries, managing player/game data persistence, or troubleshooting database issues. allowed-tools: Read, Edit, Write, Glob, Grep, Bash, mcp__context7__resolve-library-id, mcp__context7__query-docs --- # MariaDB Skill This L2J server uses MariaDB 10.4+/12.x with the `mariadb-java-client-3.1.4.jar` JDBC driver. Database access is centralized through `ConnectionPool.java` using `MariaDbPoolDataSource`. The schema contains 90+ tables covering player data, clans, events, and game state. ## Quick Start ### Get a Connection ```java import net.sf.l2j.gameserver.ConnectionPool; try (Connection con = ConnectionPool.getConnection(); PreparedStatement ps = con.prepareStatement("SELECT * FROM characters WHERE obj_Id = ?")) { ps.setInt(1, objectId); try (ResultSet rs = ps.executeQuery()) { while (rs.next()) { String name = rs.getString("char_name"); } } } catch (SQLException e) { LOGGER.error("Query failed", e); } ``` ### Connection URL Format ```properties # Game Server (Files/game/config/server.properties) URL = jdbc:mariadb://localhost:3306/toa3816?user=root&password=XXX&useUnicode=true&characterEncoding=utf-8&useSSL=false # Login Server with pool settings (Files/auth/config/loginserver.properties) URL = jdbc:mariadb://localhost:3306/toa3816?user=root&password=XXX&useUnicode=true&characterEncoding=utf-8&useSSL=false&maxPoolSize=80&minPoolSize=10&maxIdleTime=120&connectTimeout=5000 ``` ## Key Concepts | Concept | Usage | Example | |---------|-------|---------| | ConnectionPool | Singleton factory for all DB access | `ConnectionPool.getConnection()` | | try-with-resources | ALWAYS use for auto-close | `try (Connection con = ...)` | | PreparedStatement | Parameterized queries (prevents SQL injection) | `ps.setInt(1, value)` | | Batch operations | Bulk inserts/updates | `ps.addBatch(); ps.executeBatch()` | | REPLACE INTO | Upsert pattern (insert or update) | `REPLACE INTO table (pk, val) VALUES (?, ?)` | ## Common Patterns ### Save Entity Pattern ```java public void storeMe() { try (Connection con = ConnectionPool.getConnection(); PreparedStatement ps = con.prepareStatement("UPDATE characters SET level=?, exp=? WHERE obj_Id=?")) { ps.setInt(1, _level); ps.setLong(2, _exp); ps.setInt(3, _objectId); ps.executeUpdate(); } catch (SQLException e) { _log.warning("Failed to save: " + e.getMessage()); } } ``` ### Load Entity Pattern ```java public void restoreMe() { try (Connection con = ConnectionPool.getConnection(); PreparedStatement ps = con.prepareStatement("SELECT * FROM characters WHERE obj_Id=?")) { ps.setInt(1, _objectId); try (ResultSet rs = ps.executeQuery()) { if (rs.next()) { _level = rs.getInt("level"); _exp = rs.getLong("exp"); } } } catch (SQLException e) { _log.warning("Failed to load: " + e.getMessage()); } } ``` ## See Also - [patterns](references/patterns.md) - Query patterns, batch operations, connection handling - [workflows](references/workflows.md) - Schema changes, migrations, database setup ## Related Skills - See the **database-schema** skill for table structures and relationships - See the **configuration-management** skill for database URL configuration - See the **java** skill for try-with-resources and exception handling ## Documentation Resources > Fetch latest MariaDB documentation with Context7. **How to use Context7:** 1. Use `mcp__context7__resolve-library-id` to search for "mariadb" 2. **Prefer website documentation** (IDs starting with `/websites/`) over source code repositories 3. Query with `mcp__context7__query-docs` using the resolved library ID **Library ID:** `/mariadb-corporation/mariadb-docs` **Recommended Queries:** - "MariaDB Java JDBC prepared statements" - "MariaDB connection pooling configuration" - "MariaDB batch insert performance"