GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - aaberg/sql2o: sql2o is a small library, which makes it easy to convert the result of your sql-statements into objects. No resultset hacking required. Kind of like an orm, but without the sql-generation capabilities. Supports named parameters.

BranchesTags
Open more actions menu

Latest commit

 

History

738 Commits
738 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
core
core
 
 
extensions
extensions
 
 
.editorconfig
.editorconfig
 
 
.gitignore
.gitignore
 
 
README.md
README.md
 
 
docker-compose.yml
docker-compose.yml
 
 
licence.txt
licence.txt
 
 
pom.xml
pom.xml
 
 

Repository files navigation

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

  • Sql2o 1.9.0 and newer is only compatible with Java 17 or later because it adds support for records.
  • If you use Java 11, sql2o 1.8.x is compatible.
  • If you are still on Java 8, use sql2o 1.6.x.

Announcements

  • 2024-03-12 | Sql2o 1.7.0 was released

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.

About

sql2o is a small library, which makes it easy to convert the result of your sql-statements into objects. No resultset hacking required. Kind of like an orm, but without the sql-generation capabilities. Supports named parameters.

sql2o.org

Resources

Readme
MIT license
Activity

Stars

1.2k stars

Watchers

52 watching

Forks

226 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.