|
1 | | -# sql2o [](https://github.com/aaberg/sql2o/actions) [](https://search.maven.org/search?q=g:org.sql2o%20a:sql2o) |
| 1 | +# sql2o   |
2 | 2 |
|
| 3 | +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. |
3 | 4 |
|
4 | | -Sql2o is a small java library, with the purpose of making database interaction easy. |
5 | | -When fetching data from the database, the ResultSet will automatically be filled into your POJO objects. |
6 | | -Kind of like an ORM, but without the SQL generation capabilities. |
7 | | -Sql2o requires at Java 7 or 8 to run. Java versions past 8 may work, but is currently not supported. |
| 5 | +Sql2o is compatible with **Java 8 and later versions**, including Java 11 and 17. |
8 | 6 |
|
9 | | -# Announcements |
10 | | -*2024-03-12* | [Sql2o 1.7.0 was released](https://github.com/aaberg/sql2o/discussions/365) |
| 7 | +## Announcements |
11 | 8 |
|
| 9 | +- *2024-03-12* | [Sql2o 1.7.0 was released](https://github.com/aaberg/sql2o/discussions/365) |
12 | 10 |
|
13 | | -# Examples |
| 11 | +## Quick Start Example |
14 | 12 |
|
15 | | -Check out the [sql2o website](http://www.sql2o.org) for examples. |
| 13 | +Here's a basic example demonstrating how to use Sql2o to interact with a database: |
16 | 14 |
|
17 | | -# Coding guidelines. |
| 15 | +```java |
| 16 | +import org.sql2o.*; |
| 17 | + |
| 18 | +public class Main { |
| 19 | + public static void main(String[] args) { |
| 20 | + String url = "jdbc:h2:mem:test"; // Example using H2 in-memory database |
| 21 | + try (Sql2o sql2o = new Sql2o(url, "username", "password"); |
| 22 | + Connection con = sql2o.open()) { |
| 23 | + |
| 24 | + con.createQuery("CREATE TABLE users (id INTEGER PRIMARY KEY, name VARCHAR(50))").executeUpdate(); |
| 25 | + con.createQuery("INSERT INTO users (id, name) VALUES (:id, :name)") |
| 26 | + .addParameter("id", 1) |
| 27 | + .addParameter("name", "Alice") |
| 28 | + .executeUpdate(); |
| 29 | + |
| 30 | + User user = con.createQuery("SELECT * FROM users WHERE id = :id") |
| 31 | + .addParameter("id", 1) |
| 32 | + .executeAndFetchFirst(User.class); |
| 33 | + |
| 34 | + System.out.println("User: " + user.name); |
| 35 | + } |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +class User { |
| 40 | + public int id; |
| 41 | + public String name; |
| 42 | +} |
| 43 | +``` |
| 44 | + |
| 45 | +## Coding Guidelines |
| 46 | + |
| 47 | +When contributing to Sql2o, please follow [these coding guidelines](https://github.com/aaberg/sql2o/wiki/Coding-guidelines). |
| 48 | + |
| 49 | + |
| 50 | +## Wiki |
| 51 | + |
| 52 | +For additional information, check out the [Sql2o Wiki](https://github.com/aaberg/sql2o/wiki). |
18 | 53 |
|
19 | | -When hacking sql2o, please follow [these coding guidelines](https://github.com/aaberg/sql2o/wiki/Coding-guidelines). |
|
0 commit comments