The SQL Object extension sits atop Core, and provides a declarative interface. Tell Jdbi what SQL to execute and the shape of the results you like by declaring an annotated Java interface, and it will provide the implementation.
// Define your own declarative interface
public interface UserDao {
@SqlUpdate("CREATE TABLE user (id INTEGER PRIMARY KEY, name VARCHAR)")
void createTable();
@SqlUpdate("INSERT INTO user(id, name) VALUES (?, ?)")
void insertPositional(int id, String name);
}
JDBI usually requires three steps to get to a result:
There are couple of reasons why should you prefer it over Hibernate:
The Core API provides a fluent, imperative interface. Use Builder style objects to wire up your SQL to rich Java data types.
List<Users> users = handle.createQuery("select * from users where name = :name and id = :id")
.bind(0, "Tom")
.bind("id", 1)
.map(Users.class)
.list();
There are many benefits of JDBI Library.
Some of them are :
JDBI exposes relational database access in two different style APIs