Class SqlBuilder

java.lang.Object
org.ujorm.tools.jdbc.JdbcBuilder
org.ujorm.tools.sql.SqlBuilder
All Implemented Interfaces:
Serializable

public class SqlBuilder extends JdbcBuilder
Deprecated.
Use the SqlParamBuilder class rather from the release 2.26.
PrepareStatement builder support

How to use a SELECT

 SqlBuilder sql = new SqlBuilder()
     .select("t.id", "t.name")
     .from("testTable t")
     .where()
     .andCondition("t.name", "=", "Test")
     .andCondition("t.created", ">=", someDate);
 for (ResultSet rs : sql.executeSelect(dbConnection)) {
      int id = rs.getInt(1);
      String name = rs.getString(2);
 }
 

How to use a INSERT

 SqlBuilder sql = new SqlBuilder()
     .insert("testTable")
     .write("(")
     .columnInsert("id", 10)
     .columnInsert("name", "Test")
     .columnInsert("date", someDate)
     .super.write(")");
 sql.executeUpdate(dbConnection);
 

How to use a UPDATE

 SqlBuilder sql = new SqlBuilder()
     .update("testTable")
     .columnUpdate("name", "Test")
     .columnUpdate("date", SOME_DATE)
     .where()
     .andCondition("id", "IN", 10, 20, 30)
     .andCondition("created BETWEEN ? AND ?", null, someDate, someDate.plusMonths(1))
     .andCondition("name", "IS NOT NULL")
 sql.executeUpdate(dbConnection);
 
For more information see a jUnit test.
Author:
Pavel Ponec
See Also: