Skip to content

Wrapper to simplify working with JDBC

License

Notifications You must be signed in to change notification settings

itsallcode/simple-jdbc

Repository files navigation

simple-jdbc

Wrapper to simplify working with JDBC.

This project is at an early development stage and the API will change without backwards compatibility.

Java CI CodeQL Quality Gate Status Coverage Reliability Rating Security Rating Vulnerabilities Maven Central

Usage

This project requires Java 17 or later.

Add dependency to your gradle project:

dependencies {
    implementation 'org.itsallcode:simple-jdbc:0.8.0'
}
// Define a model record or class
record Name(int id, String name) {
    Object[] toRow() {
        return new Object[] { id, name };
    }
}

import org.itsallcode.jdbc.ConnectionFactory;
import org.itsallcode.jdbc.SimpleConnection;
import org.itsallcode.jdbc.resultset.SimpleResultSet;

// Execute query and fetch result
ConnectionFactory connectionFactory = ConnectionFactory.create();
try (SimpleConnection connection = connectionFactory.create("jdbc:h2:mem:", "user", "password")) {
    connection.executeScript(readResource("/schema.sql"));
    connection.batchInsert(Name.class)
        .into("NAMES", List.of("ID", "NAME"))
        .rows(Stream.of(new Name(1, "a"), new Name(2, "b"), new Name(3, "c")))
        .mapping(Name::setPreparedStatement)
        .start();
    try (SimpleResultSet<Row> rs = connection.query("select * from names order by id")) {
        List<Row> result = rs.stream().toList();
        assertEquals(3, result.size());
        assertEquals(1, result.get(0).get(0).value());
    }
}

Development

Check if dependencies are up-to-date

./gradlew dependencyUpdates

Building

Install to local maven repository:

./gradlew publishToMavenLocal

Test Coverage

To calculate and view test coverage:

./gradlew check jacocoTestReport
open build/reports/jacoco/test/html/index.html

Publish to Maven Central

Preparations

  1. Checkout the main branch, create a new branch.
  2. Update version number in build.gradle and README.md.
  3. Add changes in new version to CHANGELOG.md.
  4. Commit and push changes.
  5. Create a new pull request, have it reviewed and merged to main.

Perform the Release

  1. Start the release workflow
  • Run command gh workflow run release.yml --repo itsallcode/simple-jdbc --ref main
  • or go to GitHub Actions and start the release.yml workflow on branch main.
  1. Update title and description of the newly created GitHub release.
  2. After some time the release will be available at Maven Central.