-
Notifications
You must be signed in to change notification settings - Fork 0
Database Setup
Santiago Escobares edited this page Apr 5, 2025
·
1 revision
Database class, as well as the rest of classes, don't provide a public constructor for instantiation. Therefore, you will access them via static methods called "builders" or "creators".
In order to set up a new database connection, the following are the database parameters that you MUST provide always
Database database = Database.builder()
.host("localhost")
.port(3306)
.name("database-name")
.username("root")
.password("");You may pass additional parameters to JDBC URL
database.withOptions(
Database.Options.builder()
.append("useSSL", "true")
.append("serverTimezone", "America/Argentina/Cordoba")
);Additional optional HikariCP settings
database.dataSourceName("org.postgresql.ds.PGSimpleDataSource") // Example for PostgreSQL
.poolName("sql-db-1")
.maxPoolSize(10)
.connectionTimeout(30_000L)
.idleTimeout(30_000L)
.keepAlive(30_000L)
.maxLifetime(60_000L)
.executorService(Executors.newSingleThreadExecutor());Finally, connect to database
database.connect();If you are done and you want to terminate the database service
database.shutdown();In case you need to obtain a Connection instance, just call the static method Database.getConnection() once connected.