Skip to the content.

JSQL

License

MIT licensed.

Abstract

Welcome to JSQL. It’s a lightweight JDBC DSL framework, JSQL means Just SQL and without ORM configuration. It is a framework which is convenience and easy to use, just like sql syntax that you feel free to write SQL as usual and makes Java SQL development more easier.

If you are a Java developer searching for the jdbc framework satisfy functions as connection pool, super lightweight orm and want to write sql like java code programing, then I suggest you could try to use JSQL framework for jdbc operation.

JSQL for Reasons:

Requirements

Features

  1. Connection/JdbcExecutor pool
  2. SQL syntax like builder
  3. Transaction
  4. Support customizing dialects
  5. Pagination
  6. Jdbc executor for query, update or batch update
  7. Super lightweight ORM
  8. Against SQL inject
  9. Logging ability

Support Databases

  1. Cubrid
  2. SQLite
  3. DB2
  4. Derby (EmbeddedDerby/NetworkDerby)
  5. H2
  6. MariaDB
  7. MySQL
  8. Oracle
  9. PostgreSQL
  10. SQLServer2012(version >= 2012)

Quick Start

Maven dependency

<!-- for jdk1.8+ -->
<dependency>
  <groupId>cn.icuter</groupId>
  <artifactId>jsql</artifactId>
  <version>1.1.2</version>
</dependency>

<!-- for jdk1.6+ -->
<dependency>
  <groupId>cn.icuter</groupId>
  <artifactId>jsql-jdk1.6</artifactId>
  <version>1.1.2</version>
</dependency>

Examples

Auto Commit

JSQLDataSource dataSource = JSQLDataSource.newDataSourceBuilder()
                            .url("jdbcUrl").user("jsql").password("pass").build();
List<Map<String, Object>> list = dataSource.select()
                                           .from("table")
                                           .where().eq("name", "jsql")
                                           .execQuery();
SQL: select * from table where name = ?
Value: [jsql]

Transaction

JSQLDataSource dataSource = JSQLDataSource.newDataSourceBuilder()
                            .url("jdbcUrl").user("jsql").password("pass").build();
dataSource.transaction(tx -> {
    tx.insert("table")
      .values(Cond.eq("col1", "val1"), Cond.eq("col2", 102),Cond.eq("col3", "val3"))
      .execUpdate();
    // if exception thrown will call tx.rollback()
    // tx.commit(); // auto commit if transaction ended
});
SQL: insert into table(col1,col2,col3) values(?,?,?)
VALUE: ["val1", 102, "val3"]

Using standalone Transaction to control commit or rollback operation as your favour

JSQLDataSource dataSource = JSQLDataSource.newDataSourceBuilder()
                            .url("jdbcUrl").user("jsql").password("pass").build();
TransactionDataSource tx = dataSource.transaction();
tx.insert("table")
  .values(Cond.eq("col1", "val1"), Cond.eq("col2", 102),Cond.eq("col3", "val3"))
  .execUpdate();
tx.close(); // auto commit
SQL: insert into table(col1,col2,col3) values(?,?,?)
VALUE: ["val1", 102, "val3"]

NOTE

Above examples are using JSQLDataSource inner Connection pool to execute SQL generated by JSQL.

Documents

Find more documentation here.

  1. DataSource
  2. JDBC Connection Pool
  3. Transaction
  4. SQL Builder
  5. Condition
  6. DB Dialect
  7. ORM
  8. SQL Executor
  9. Logging Customization

Release Notes

1.1.2

performance

features

others

1.1.1

bug fixes

performance

1.1.0

bug fixes

performance

1.0.9

bug fixes

1.0.8

features

1.0.7

bug fixes

1.0.6

bug fixes

features

1.0.4

bug fixes

features

jsql-jdk1.6 missing this version

1.0.3

breaks

bug fixes

features

jsql-jdk1.6 missing this version