Skip navigation links

Package net.pterodactylus.util.database

Helper and abstraction classes for database interaction.

See: Description

Package net.pterodactylus.util.database Description

Helper and abstraction classes for database interaction.

Database Backends

The Database interface defines data manipulation methods that can be used to perform 95% of all necessary interaction with the database.

Getting a Single Value from the Database

The Database.getSingle(Query, ObjectCreator) method is used to return a single value or object from the database. This method delegates the work of actually creating the return value to the given ObjectCreator instance which uses the first row that is returned by the given query to create the appropriate object.

Getting Multiple Values from the Database

The Database.getMultiple(Query, ObjectCreator) method is used to return multiple values or objects from the database. Again, the actual creation process is delegated to the given object creator which will be used for every row the query returns.

Inserting Values into the Database

Use the Database.insert(Query) method to execute a query that will insert one new record into a database. It will return the first auto-generated ID, or -1 if no ID was generated.

Updating Values in the Database

Finally, the Database.update(Query) method will let you execute a query that updates values in the database. It will return the number of changed records.

The AbstractDatabase Implementation

This class introduces some helper classes the perform the actual SQL queries and reduces the cost of writing new database backends to the implementation of two methods: getConnection() and returnConnection() . It also contains a method to create a database from a DataSource ( AbstractDatabase.fromDataSource(javax.sql.DataSource) ).

The Query Class

This class stores an SQL query string and its parameters. It is able to create a PreparedStatement from the parameters and it can be persisted easily.

The ObjectCreator Class

An object creator is responsible for creating objects from the current row of a ResultSet. It is used by the helper classes in AbstractDatabase to allow the user to control the conversion from a result set to a domain-specific object.

Skip navigation links

Copyright © 2026. All rights reserved.