Skip to content

terma/sql-on-json

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sql-on-json

Build Status Maven Central

How to use

try (Connection c = new SqlOnJson().convertPlain("{a:[{id:12000,name:\"super\"},{id:90,name:\"remta\"}]}")) {
    ResultSet rs = c.prepareStatement("select * from a").executeQuery();
    while (rs.next()) {
        // my business logic
    }
}

Use non default DB

By default sql-on-json uses HSQLDB

final SqlOnJson sqlOnJson = new SqlOnJson("driver-class", "url", "user", "password");
try (Connection c = sqlOnJson.convertPlain("{a:[{id:12000,name:\"super\"},{id:90,name:\"remta\"}]}")) {
    ...
}

For example you can use H2

final SqlOnJson sqlOnJson = new SqlOnJson("org.h2.Driver", "jdbc:h2:mem:", "", "");
try (...)

To make DB URL unique per new SqlOnJson(...) you can use placeholder <INSTANCE_ID> in second parameter of constructor url, for HSQLDB it will be jdbc:hsqldb:mem:sql_on_json_<INSTANCE_ID>;shutdown=true