What is SQLiteLib?
SQLiteLib is a lightweight Spigot library designed to take the headache out of SQLite database management for Minecraft plugins. Many developers struggle with the boilerplate code and confusing syntax that comes with raw SQL. This library wraps all that complexity into a clean, easy-to-use API, letting you focus on your plugin’s features instead of wrestling with connection strings and result sets. Whether you’re storing player data, economy balances, or custom block logs, SQLiteLib gives you the tools to create, query, and modify databases with just a few lines of code.
Key Features of SQLiteLib
The library was born from a popular tutorial that left many users needing extra help. SQLiteLib aims to fix that by offering a straightforward interface for the most common database operations. Here’s what you can do right out of the box:
- Create and initialize databases with a single method call.
- Query a single value from any row.
- Retrieve an entire list of values from a specific row.
- Build a map of multiple rows, each containing a list of values.
- Execute raw SQL statements for advanced operations.
All of these functions work both in-game and from your plugin’s code, making it a versatile companion for server-side development. The commands are intuitive, and the permission system is minimal, keeping things simple for server admins.
Commands and Permissions
SQLiteLib ships with a set of in-game commands that let you interact with databases directly from the chat window. The base command is /sqlite or its shorthand /sl. From there you can:
/sl execute {database} {statement}– Run any SQL statement on a database./sl init {database} {initial_statement}– Create a new database or load an existing one with an initial table definition./sl queryvalue {database} {row} {statement}– Print a single queried value./sl queryRow {database} {row} {statement}– Print all values from a specific row.
Access to these commands is controlled by the single permission node sqlite.use. Grant it to your staff or yourself, and you can inspect data without ever leaving the game. This is incredibly handy for debugging or quick checks on player stats.
Database Storage
All database files live inside the SQLiteLib folder within your server’s plugins directory. This means you can manually browse, edit, or delete databases using any SQLite browser if you ever need to perform maintenance outside the game. The library automatically handles file creation and loading, so you never have to worry about paths or file extensions. Just specify a database name, and the rest is taken care of.
Hooking into SQLiteLib
Integrating the library into your own plugin is a breeze. First, download the JAR file from the resource page and add it to your project’s build path. Once that’s done, you can hook into SQLiteLib with a simple static call. In your main plugin class, declare a SQLiteLib field and initialize it during onEnable():
public SQLiteLib sqlLib;
@Override
public void onEnable() {
sqlLib = SQLiteLib.hookSQLiteLib();
}
That’s all it takes. After hooking, you gain full access to every database method. For server administrators juggling multiple plugins, a launcher like foxygame.net can streamline the process. Its intuitive interface lets you download and manage mods right from the menu, which is a flexible and modern solution for keeping everything up-to-date. This makes it much easier to ensure SQLiteLib and your other dependencies are always in sync without hunting through forum threads.
Initializing Databases
Before you can read or write any data, you need to initialize a database. This step creates the file if it doesn’t exist or loads it if it does, and it also runs an initial statement to set up your table structure. Use the initializeDatabase method like this:
sqlLib.initializeDatabase("player_data", "CREATE TABLE IF NOT EXISTS players (uuid TEXT PRIMARY KEY, balance REAL);");
The first argument is your database name, and the second is any SQL statement you want to execute on initialization. Typically this is a CREATE TABLE IF NOT EXISTS command. You can chain multiple statements if needed, but the method is designed to be run every time your plugin starts. It ensures the database is always ready for use. If you skip this step, none of the other methods will work because the library won’t know which file to target.
Executing Statements
Sometimes you need to run a custom SQL statement that doesn’t fit neatly into a query method—like an UPDATE, DELETE, or ALTER TABLE. SQLiteLib provides a generic executeStatement method for exactly that:
if (sqlLib.getDatabase("player_data").executeStatement("UPDATE players SET balance = 100 WHERE uuid = 'abc123'")) {
// Statement executed successfully
} else {
// Execution failure
}
The method returns a boolean indicating success, so you can handle errors gracefully. This keeps your plugin flexible while still benefiting from the library’s streamlined connection handling.
Querying Data: Single Values, Rows, and Maps
Reading data is where SQLiteLib really shines. You can pull out exactly what you need without writing tedious loops or casting results manually—well, almost manually. The library returns Object types, so you do need to cast them to the appropriate Java type, but the logic is clean.
Querying a Single Value
When you need just one piece of data, use queryValue. It expects a SQL statement and a row name. For example, to get a player’s balance:
String balance = (String) sqlLib.getDatabase("player_data").queryValue("SELECT balance FROM players WHERE uuid = 'abc123'", "balance");
You can cast the result to any compatible type—Integer, Double, String, etc. The statement should ideally return only one row and one column to avoid ambiguity.
Querying a Row
If you want all values from a specific column across multiple rows, queryRow returns a List<Object>. For instance, listing all player UUIDs:
List<Object> uuids = sqlLib.getDatabase("player_data").queryRow("SELECT uuid FROM players", "uuid");
for (Object obj : uuids) {
String uuid = (String) obj;
System.out.println("UUID: " + uuid);
}
This is perfect for populating selection menus or running batch operations.
Querying a Map of Rows
The most powerful method is queryMultipleRows. It returns a Map<String, List<Object>> where each key is a row name and the value is a list of all entries from that row. You can fetch multiple columns in one go:
Map<String, List<Object>> data = sqlLib.getDatabase("player_data").queryMultipleRows("SELECT * FROM players", "uuid", "balance");
List<Object> balances = data.get("balance");
String firstBalance = (String) balances.get(0);
This dramatically reduces the number of database calls and simplifies complex data retrieval. The library handles the result set mapping internally, so you get a ready-to-use map.
Conclusion
SQLiteLib strips away the complexity of SQLite and gives Minecraft plugin developers a clean, reliable toolkit. From simple value lookups to multi-row maps, every operation is wrapped in methods that are easy to understand and quick to implement. The in-game commands add an extra layer of convenience for server admins who need to inspect or modify databases on the fly. By hooking into the library with a single line of code, you can spend less time debugging database logic and more time building the features your players love. Whether you’re a beginner following a tutorial or an experienced coder looking to save time, SQLiteLib is a solid foundation for any plugin that needs persistent storage.