Back to mods
Database Utils project artwork

Modrinth · Minecraft mod

Database Utils

A simple mod for developers to make database usage easier

Choose a version Pick your version below, then grab the matching file.

Quick answer

Which Database Utils release matches 26.2 Fabric?

Updated 4 months ago
Best match for your filters 1.0.0+26.1
Game version 26.1, 26.1.1, 26.1.2
Loader Fabric

Database Utils 1.0.0+26.1 targets 26.1, 26.1.1, 26.1.2 with Fabric. Installation on the client is optional. Installation on the dedicated server is optional. No extra mods listed for this file.

Where it goes

Is Database Utils required on the client, server, or both?

Installation on the client is optional. Installation on the dedicated server is optional.

Client Optional
Dedicated server Optional
Loader for this release Fabric
Required install it here Optional supported, not mandatory Not supported do not install here Source doesn’t say do not assume

The source marks this as usable on both the client and server.

What else does Database Utils 1.0.0+26.1 need?

1.0.0+26.1 on 26.2 Fabric. Every mod below is checked against that same setup.

No extra mods listed for this file

This file does not list any required mods. Do not add a library just because a different file uses it.

This file does not list any required or optional mods.

Before you install it

Add Database Utils without breaking your instance.

Built for Database Utils 1.0.0+26.1 on 26.2 Fabric. Pick another file and the loader, install side or required mods may change.

  1. 01

    Stick to this file

    Use 1.0.0+26.1. It targets 26.1, 26.1.1, 26.1.2 with Fabric; another release may have different loader, side or dependency requirements.

  2. 02

    Bring the mods it needs

    This file does not list any required mods. Do not add a library just because a different file uses it.

  3. 03

    Put it on the correct side

    Installation on the client is optional. Installation on the dedicated server is optional.

  4. 04

    Pick the file you checked

    Use the “Get this file” button beside 1.0.0+26.1. It opens that exact file at the source.

About this project

What does Database Utils add?

Database Utils


🔎 Explanations

This mod includes some utilities for working with databases.
The most popular connectors are included directly in the mod JAR, which avoids having to import them into each mod and helps reduce the overall size of your projects.

To import this library, you must add the following to your build.gradle file.

repositories {
    maven { url "https://api.modrinth.com/maven" }
}

dependencies {
    implementation "maven.modrinth:database-utils:1.0.0"
}

🖥️ Usage

Configuration is managed by this library. By using the following line, a .properties file is automatically created (if it does not already exist) and loaded from the config folder.

Config config = new Config(MOD_ID);

In this example, the file will be named MOD_ID.properties.
Here is an example configuration file.

storage=postgres
host=127.0.0.1
port=5432
database=minecraft_db
user=user
password=password
Key Description
storage Database type. Must be one of: postgres, mysql, mariadb, sqlite, or test.
host IP address or hostname of the database server
port Port used by the database server.
database Name of the database.
user User used to connect to the database.
password Password of the user.

Then, you need to define your own class MyCustomDB, which extends DatabaseQueries.
This class is intended to contain all SQL related methods.
In this context, you have access to some method from DatabaseQueries, such as getType, which help you create an implementation compatible with multiple databases.

public class MyCustomDB extends DatabaseQueries {

    public MyCustomDB(Database db) {
        super(db);
    }
    
    @Override
    public void init() {
        try (Connection connection = getConnection()) {
            /* ... */
        } catch (SQLException | DatabaseLinkException e) {
            LOGGER.error("Unable to initialize: {}", e.getMessage());
        }
    }
    
    /* other methods */
    
    public void someMethod() {
        /* ... */
    }
}

You will also need to create a database instance. This is where the Config object is used. The following code snippet retrieves the database defined in the configuration and initializes your DatabaseQueries implementation.

Database database = DatabaseUtils.getDatabase(config);
MyCustomDB custom = new MyCustomDB(database);

You can now call any query defined in your DatabaseQueries implementation through your custom instance.

custom.someMethod();

Project description from Modrinth.

Pick your setup

Database Utils by Minecraft version and loader

Choose the version and loader you play, then open the matching release.

23 available setups

Showing the newest 12 of 23 game versions. Older files are in the list below.

Check the dependencies, then try the file in a copied instance before changing a world you care about.

Recent files

Database Utils versions and loaders

1 of 2 releases match
Clear filters

Looking for an older file? The official Modrinth project page is in Resources.