Skip to content

Commit 01ef698

Browse files
authored
Merge pull request #378 from FXV6624/update-readme
Improved README with examples and updated compatibility
2 parents f2f77fe + a375671 commit 01ef698

File tree

1 file changed

+45
-11
lines changed

1 file changed

+45
-11
lines changed

README.md

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,53 @@
1-
# sql2o [![Github Actions Build](https://github.com/aaberg/sql2o/actions/workflows/pipeline.yml/badge.svg)](https://github.com/aaberg/sql2o/actions) [![Maven Central](https://img.shields.io/maven-central/v/org.sql2o/sql2o.svg)](https://search.maven.org/search?q=g:org.sql2o%20a:sql2o)
1+
# sql2o  
22

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.
34

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.
86

9-
# Announcements
10-
*2024-03-12* | [Sql2o 1.7.0 was released](https://github.com/aaberg/sql2o/discussions/365)
7+
## Announcements
118

9+
- *2024-03-12* | [Sql2o 1.7.0 was released](https://github.com/aaberg/sql2o/discussions/365)
1210

13-
# Examples
11+
## Quick Start Example
1412

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:
1614

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).
1853

19-
When hacking sql2o, please follow [these coding guidelines](https://github.com/aaberg/sql2o/wiki/Coding-guidelines).

0 commit comments

Comments
 (0)