This repository was archived by the owner on Sep 26, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Query builders
Maarten Zuidhoorn edited this page Nov 1, 2016
·
3 revisions
To make writing queries easier, you can use query builders, for some common tasks.
For the SELECT query, begin by creating a SelectQuery object:
SelectQuery selectQuery = new SelectQuery(String table);selectQuery.column(String column);To select multiple columns, just use the method multiple times, or to select all columns you can simply use "*".
selectQuery.where(String expression);
selectQuery.and(String expression); //Alias for .where()selectQuery.orderBy(String column, boolean ascending);selectQuery.limit(int offset, int rowCount);
selectQuery.limit(int rowCount);If you don't set the offset, it will be set to 0, which is the default.
To create a String to use in a Query, call the build() method.
You can use the query builders in a builder-like way as well, like this:
String sql = new SelectQuery("table").column("myColumn").where("id = ?").build();Begin by making a CreateTableQuery object, like this:
CreateTableQuery createTableQuery = new CreateTableQuery();createTableQuery.ifNotExists();createTableQuery.column(String column, String settings);createTableQuery.primaryKey(String column);