SQLG2 Java Preprocessor 1.4

  • submit to reddit

New release of SQLG2 preprocessor allows Java developers easily use plain SQL for DB interaction. This release requires JDK 1.6 or later.

New features:

  • Improved type safety
  • Database meta-data retrieval
  • Custom DB-to-Java mapping

SQLG2 is the tool for those who think relationally and do not like ORMs. If you know SQL (and PL/SQL, as the primary target is Oracle) then SQLG2 code should seem quite natural:

@RowType
public abstract static class EmpRow {
}

@Business
public List<EmpRow> selectAll()
throws SQLException {
/**
* SELECT * FROM EMP ORDER BY EMP_NO
*/
@Prepare PreparedStatement stmt = null;
return multiRowQuery(stmt, EmpRow.class);
}

And this SQL is checked at preprocess-time, giving you almost complete safety at runtime.
Required runtime library is a very thin wrapper over JDBC - it is less than 70 KB with no external dependencies.

See also project documentation.

0
Average: 2 (1 vote)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

Thomas Mueller replied on Wed, 2008/12/24 - 4:56am

Are dynamic statements supported? Example:
find(Integer id, String firstName, String lastName) {
    String sql = "SELECT * FROM ADDRESS WHERE 1=1";
    if (id != null) sql += " AND ID=?";
    if (firstName != null) sql += " AND FIRST_NAME=?";
    ...
}

Oleg Sobolev replied on Wed, 2008/12/24 - 3:27pm

Yes, see different use cases: http://sqlg2.sourceforge.net/ch2.html#case3

Thomas Mueller replied on Wed, 2008/12/24 - 4:51pm

Thanks for the link! The problem is, in that case SQL injection is still possible, and I don't think the preprocessor can check the syntax any longer. On the other hand, dynamic statements are not that common.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.