This framework works with native SQL and makes easier to transform database data into Java objects.
The code of the project in this page can be found in here: https://github.com/uaihebert/sql2oCrud
sql2o has a Connection class that is very easy to create:
Notice that we have a static Sql2o object that will work like a Connection factory.
To read the database data we would do something like:
Notice that we have a Native SQL written, but we have named parameters. We are not using positional parameters like ‘?1′ but we gave a name to the parameter like ‘:id’. We can say that named parameters has the advantage that we will not get lost in a query with several parameters; when we forget to pass some parameter the error message will tell us the parameter name that is missing.
We can inform in the query the name of the column with a different name, there is no need to create a Mapper/RowMapper. With the return type defined in the query we will not need to instantiate manually the object, sql2o will do it for us.
If you want to update, delete or insert data in the database you can do like below:
It is a “very easy to use” framework.
About the sql2o we can say that:
Easy to handle scalar query: the returned values of SUM, COUNT functions are easy to handle
Named parameters in query: Will make easy to handle SQL with a lot of parameters
Binding functions: bind is a function that will automatically populate the database query parameters through a given object, unfortunately it did not work in this project for a problem with the enum. I did not investigate the problem, but I think that it is something easy to handle