dev.club — where best developers and top companies connect.

dev.club — where best developers and top companies connect.Invite only

Request invite

sql2o Github Actions Build Maven Central

Sql2o is a lightweight Java library designed to simplify database interaction. It automatically maps query results into POJO objects, providing an easy-to-use alternative to ORMs, without SQL generation capabilities.

Java versions

Announcements

Quick Start Example

Here's a basic example demonstrating how to use Sql2o to interact with a database:

import org.sql2o.*;

public class Main {
    public static void main(String[] args) {
        String url = "jdbc:h2:mem:test"; // Example using H2 in-memory database
        try (Sql2o sql2o = new Sql2o(url, "username", "password");
             Connection con = sql2o.open()) {
            
            con.createQuery("CREATE TABLE users (id INTEGER PRIMARY KEY, name VARCHAR(50))").executeUpdate();
            con.createQuery("INSERT INTO users (id, name) VALUES (:id, :name)")
                .addParameter("id", 1)
                .addParameter("name", "Alice")
                .executeUpdate();
            
            User user = con.createQuery("SELECT * FROM users WHERE id = :id")
                            .addParameter("id", 1)
                            .executeAndFetchFirst(User.class);
            
            System.out.println("User: " + user.name);
        }
    }
}

class User {
    public int id;
    public String name;
}

Coding Guidelines

When contributing to Sql2o, please follow these coding guidelines.

Wiki

For additional information, check out the Sql2o Wiki.

Join libs.tech

...and unlock some superpowers

GitHub

We won't share your data with anyone else.