2.8 KiB
2.8 KiB
CreeperSQL
CreeperSQL is a standalone Java SQL library designed for Minecraft plugins.
It has no Bukkit/Spigot dependency, supports automatic configuration reading/creation, and provides simple SQL methods.
Features
- Pure Java MySQL library
- Automatic configuration file (
plugins/MySQLConnection/config.yml) creation - Supports all standard SQL actions: SELECT, INSERT, UPDATE, DELETE, CREATE TABLE, DROP TABLE
- Config must be set or read before connecting
- Simple, intuitive API for plugin developers
- Can be used in any Minecraft plugin project
Installation
- Build the CreeperSQL JAR (see Build section).
- Import the JAR into your plugin project:
- IntelliJ: File → Project Structure → Libraries →
+→ Java → selectCreeperSQL.jar
- IntelliJ: File → Project Structure → Libraries →
- Add MySQL Connector/J to your project if not included in the JAR.
Usage
1. Set or read configuration
- Option 1: Manual configuration
Set host, user, password, and database manually:
CreeperSQL mysql = new CreeperSQL();
mysql.setConfig("127.0.0.1:3306", "root", "password", "testdb");
- Option 2: Read from config.yml
CreeperSQL mysql = new CreeperSQL();
mysql.readMinecraftConfig();
Note: Config must be fully filled out before connecting.
2. Connect to the database
mysql.connect();
3. Execute SQL actions
getTables()→ returns a list of table names in the databasesqlAction(String sql)→ executes any SQL query, returns a QueryResult objectcreateTable(String sql)→ executes a CREATE TABLE statementdropTable(String tableName)→ drops the specified tableinsert(String sql)→ executes an INSERT statementupdate(String sql)→ executes an UPDATE statementdelete(String sql)→ executes a DELETE statementclose()→ closes the database connection
4. QueryResult Object
Returned by sqlAction():
rows→ list of rows (each row is a list of strings)affectedRows→ number of rows affected by INSERT/UPDATE/DELETEerror→ error message if SQL failedhasError()→ returns true if there was an errorhasRows()→ returns true if the query returned rows
Build Instructions
- Open IntelliJ and create a Java project (SDK 17+ recommended)
- Add
CreeperSQL.javatosrc - Add MySQL Connector/J as a library
- Create a JAR artifact:
- File → Project Structure → Artifacts →
+→ JAR → From modules with dependencies
- File → Project Structure → Artifacts →
- Build → Build Artifacts → Build
- The output JAR can now be imported into any Minecraft plugin project
Notes
- Always call
setConfig()orreadMinecraftConfig()beforeconnect() - The library is fully standalone and does not depend on Bukkit/Spigot
- For heavy queries, run on an async thread to prevent server lag