Stop to lost time writing repeated SQL queries and let Java SQL Query Builder do the job for you. It's simple, fast and lightweight. You don't need to make a connection with a database.
- 1. Installation
- 1.1. Installation with Maven
- 2. SELECT Statement
- 3. INNER JOIN statement
- 4. Author
- 5. License
1. Installation ↑
For default installation, see Releases section to download the .jar file and add it to the path of your project.
1.1. Installation with Maven ↑
To install with maven, you can use the Jitpack for that.
Step 1. Add the JitPack repository to your build file
<repositories>
...
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Step 2. Add the dependency
<dependencies>
...
<dependency>
<groupId>com.github.derickfelix</groupId>
<artifactId>jsqb</artifactId>
<version>LATEST</version>
</dependency>
</dependencies>
If the project doesn't have any GitHub Releases you can use the short commit hash or 'master-SNAPSHOT' as the version. Check the Jitpack page for more details.
2. SELECT Statement ↑
2.1. Basic SELECT statement ↑
public class Usage {
public static void main(String[] args)
{
Jsqb jsqb = new Jsqb();
String sql = jsqb.select("users").write();
System.out.println(sql);
}
}
SELECT users.* FROM users
2.2. SELECT with Specific Fields ↑
public class Usage {
public static void main(String[] args)
{
Jsqb jsqb = new Jsqb();
String sql = jsqb.select("users", "id", "name", "email").write();
System.out.println(sql);
}
}
SELECT users.id, users.name, users.email FROM users
2.2. Aliased SELECT statement ↑
The same of the previous one but with more information.
public class Usage {
public static void main(String[] args)
{
Jsqb jsqb = new Jsqb();
String sql = jsqb.select("users", "id as userId", "name as username", "email as receiver").write();
System.out.println(sql);
}
}
SELECT users.id as userId, users.name as username, users.email as receiver FROM users
3. INNER JOIN statement ↑
3.1. Simple Inner join ↑
The innerJoin()
method expects the tableName
, and the on
detail, and the fields
parameter is optional.
This method is described as:
innerJoin(String tableName, String on, String... fields)
.
public class Usage {
public static void main(String[] args)
{
Jsqb jsqb = new Jsqb();
String sql = jsqb.select("users", "id", "name", "email")
.innerJoin("roles", "roles.id = users.role_id", "name", "level")
.write();
System.out.println(sql);
}
}
SELECT users.id, users.name, users.email, roles.name, roles.level FROM users
INNER JOIN roles on roles.id = users.role_id
4. Author ↑
Derick Felix
5. License ↑
Java SQL Query Builder is licensed under the Apache license.
Copyright 2018 derickfelix.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.