Sql2o is a small java framework that makes it easy to execute sql statements on your JDBC compliant database from java.
Sql2o uses JDBC internally, so it should work with any database with a JDBC driver (*).
With sql2o you get:
- Functionality to automatically map the result set of your query with a java class, without the need of any annotations or configuration.
- support for named parameters.
- A smooth and flexible api that is a lot easier to read (and requires much lesser code) than plain JDBC.
Consider the following java class
Say you want to fetch all tasks from your database with category='foo'. The following comparison shows how this is
typically done with sql2o compared to how it is done with plain JDBC.
The mapping between columns and properties are done automatically by name. Of course this is not always possible,
so sql2o provides a simple and flexible column mapping solution.
INSERT, UPDATE and DELETE statements are also made a lot easier. Just take a look at this example.
What sql2o is not!
sql2o is not an ORM. It has no sql generation
capabilities. Don't use sql2o if you don't want to write sql.
- Automatic column to property mapping by name. Case sensitive or case-insensitive, you choose.
- Possibility to add custom column mappings if desired.
- Allows chaining of method calls, so you can do a lot of stuff on one line of code.
- Named parameters.
- Slick transaction handling.
- Ability to execute multiple queries in a batch
- Compatible with JodaTime for mapping with date/datetime/timestamp fields in your database
Check out the learn section for more examples and features.
Sql2o is tested to work with JDBC drivers for PostgreSQL, MySQL, Oracle, MS Sql Server, IBM DB2, H2 and HyperSQL.