{"id":49070,"date":"2017-08-08T11:00:01","date_gmt":"2017-08-08T08:00:01","guid":{"rendered":"http:\/\/examples.javacodegeeks.com\/?p=49070"},"modified":"2019-03-05T13:01:50","modified_gmt":"2019-03-05T11:01:50","slug":"jdbc-query-builder-tutorial","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/jdbc-query-builder-tutorial\/","title":{"rendered":"JDBC Query Builder Tutorial"},"content":{"rendered":"<p>Handling <code>SQL<\/code> within a Java application can be tricky. For one thing, Java does not support multi-line string constants, so developers can end up with code that looks like this:<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<\/p>\n<p>&nbsp;<br \/>\n<span style=\"text-decoration: underline;\"><em>Sample Code<\/em><\/span><\/p>\n<pre class=\"brush:java; wrap-lines:false;\">String sql_query = \"select *\" + \"from user_table\" + \"where name like 'Fred%'\";\n<\/pre>\n<p>This code is not just <em>ugly<\/em> but also <em>error-prone<\/em>. Did you notice the missing space between <code>user_table<\/code> and <code>where<\/code>? A further challenge when working with SQL in Java is that we often need to build the SQL dynamically.<\/p>\n<div class=\"toc\">\n<h3>Table Of Contents<\/h3>\n<dl>\n<dt><a href=\"#introduction\">1. Introduction<\/a><\/dt>\n<dd>\n<dl>\n<dt><a href=\"#jdbcIntroduction\">1.1 What is JDBC?<\/a><\/dt>\n<dt><a href=\"#crudOperations\">1.2 What are JDBC CRUD Operations?<\/a><\/dt>\n<dt><a href=\"#sqlbuilder\">1.3 SqlBuilder<\/a><\/dt>\n<dt><a href=\"#downloadAndInstallMySQL\">1.4 Download and Install MySQL<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dt><a href=\"#jdbcQueryBuilderTut\">2. JDBC Query Builder Tutorial<\/a><\/dt>\n<dd>\n<dl>\n<dt><a href=\"#tools\">2.1 Tools used<\/a><\/dt>\n<dt><a href=\"#projectStructure\">2.2 Project Structure<\/a><\/dt>\n<dt><a href=\"#projectCreation\">2.3 Project Creation<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dt><a href=\"#applicationBuilding\">3. Application Building<\/a><\/dt>\n<dd>\n<dl>\n<dt><a href=\"#dbCreation\">3.1 Database<\/a><\/dt>\n<dt><a href=\"#mavenJars\">3.2 Maven Dependencies<\/a><\/dt>\n<dt><a href=\"#javaClassCreation\">3.3 Java Class Creation<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dt><a href=\"#projectRun\">4. Run the Application<\/a><\/dt>\n<dt><a href=\"#projectDemo\">5. Project Demo<\/a><\/dt>\n<dt><a href=\"#projectConclusion\">6. Conclusion<\/a><\/dt>\n<dt><a href=\"#projectDownload\">7. Download the Eclipse Project<\/a><\/dt>\n<\/dl>\n<\/div>\n<h2><a name=\"introduction\"><\/a>1. Introduction<\/h2>\n<p>In this JDBC Query Builder example, we will see how to achieve dynamic <code>SQL<\/code> Query Builder phenomenon by using the open-source <a href=\"http:\/\/openhms.sourceforge.net\/\" target=\"_blank\" rel=\"noopener noreferrer\">Sqlbuilder<\/a> library. But before moving ahead let\u2019s take a look and understand JDBC and Sqlbuilder library.<\/p>\n<h3><a name=\"jdbcIntroduction\"><\/a>1.1 What is JDBC?<\/h3>\n<p>JDBC stands for <strong>Java Database Connectivity<\/strong>, which is a standard Java API for database-independent connectivity between the Java programming language and a wide range of databases. Using JDBC one can send <em>statements<\/em> to almost any relational database. Thus, JDBC is a Java API for executing the <code>SQL<\/code> statements and supports basic <code>SQL<\/code> functionality.<\/p>\n<p>The JDBC library includes API for each of the tasks commonly associated with the database usage,<\/p>\n<ul>\n<li>Making a connection to the database.<\/li>\n<li>Creating SQL statements.<\/li>\n<li>Executing SQL queries in the database.<\/li>\n<li>Viewing and Modifying the resulting records.<\/li>\n<\/ul>\n<p><figure id=\"attachment_49071\" aria-describedby=\"caption-attachment-49071\" style=\"width: 471px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-system-architecture-1.jpg\"><img decoding=\"async\" class=\"size-full wp-image-49071\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-system-architecture-1.jpg\" alt=\"Fig. 1: JDBC Architecture\" width=\"471\" height=\"210\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-system-architecture-1.jpg 471w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-system-architecture-1-300x134.jpg 300w\" sizes=\"(max-width: 471px) 100vw, 471px\" \/><\/a><figcaption id=\"caption-attachment-49071\" class=\"wp-caption-text\">Fig. 1: JDBC Architecture<\/figcaption><\/figure><\/p>\n<h3><a name=\"crudOperations\"><\/a>1.2 What are JDBC CRUD Operations?<\/h3>\n<p><strong>CRUD<\/strong> means the basic <b>operations<\/b> to be done in a data repository. We directly handle records or data objects; apart from these operations, the records are passive entities. CRUD stands for <em>Create<\/em>, <em>Read<\/em>, <em>Update<\/em> and <em>Delete<\/em>. The CRUD functions are the user interfaces to databases, as they permit users to create, view, modify and alter data. CRUD works on entities in databases and manipulates these entities.<\/p>\n<p>For instance, a student database table adds (creates) new student details, accesses (reads) existing student details, modifies (updates) existing student data such as subjects, and deletes student details when students leave the school.<\/p>\n<p>The commands corresponding to these operations in SQL are INSERT, SELECT, UPDATE and DELETE. <strong>INSERT<\/strong> adds new records, <strong>SELECT<\/strong> retrieves or selects existing records based on selection conditions, <strong>UPDATE<\/strong> modifies existing records, and <strong>DELETE<\/strong> removes tables or records in a table.<\/p>\n<p><figure id=\"attachment_49072\" aria-describedby=\"caption-attachment-49072\" style=\"width: 515px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-system-architecture-2.jpg\"><img decoding=\"async\" class=\"size-full wp-image-49072\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-system-architecture-2.jpg\" alt=\"Fig. 2: CRUD (Create, Read, Update, Delete) Operations\" width=\"515\" height=\"271\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-system-architecture-2.jpg 515w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-system-architecture-2-300x158.jpg 300w\" sizes=\"(max-width: 515px) 100vw, 515px\" \/><\/a><figcaption id=\"caption-attachment-49072\" class=\"wp-caption-text\">Fig. 2: CRUD (Create, Read, Update, Delete) Operations<\/figcaption><\/figure><\/p>\n<h4>1.2.1 CRUD Benefits<\/h4>\n<p>Using the database operations in an application has some advantages i.e.<\/p>\n<ul>\n<li>Improves data security and data access to users by using host and query languages.<\/li>\n<li>Greater data integrity and independence of applications programs.<\/li>\n<li>Improves application performance by reducing the data redundancy.<\/li>\n<\/ul>\n<h3><a name=\"sqlbuilder\"><\/a>1.3 SqlBuilder<\/h3>\n<p><strong>SqlBuilder<\/strong> is a library which attempts to take the pain out of generating <code>SQL<\/code> queries within the Java programs. Using one programming language (Java) to generate code for another language (i.e. <code>SQL<\/code>) is always a challenge.<\/p>\n<p>There are always issues with the escaping characters within the string literals, getting spaces in the right place, and getting the parentheses to match up. And often, even after the code is debugged and fully tested, it is still very fragile. The slightest change will throw things out of balance and require another round of testing and tweaking.<\/p>\n<p><em>SqlBuilder&nbsp;<\/em>changes that whole scenario by wrapping the <code>SQL<\/code> syntax within very lightweight and easy to use Java objects which follow the <span style=\"text-decoration: underline;\">builder<\/span> paradigm (similar to <code>StringBuilder<\/code> in Java). This changes many common <em>SQL syntactical runtime errors<\/em> into <em>Java compile-time errors.<\/em><\/p>\n<p>Let&#8217;s dive right into some quick examples to see how it all works.<\/p>\n<h4>1.3.1 Sqlbuilder SelectQuery Example<\/h4>\n<p>A fairly simple <code>SQL<\/code> select query embedded in a Java program might currently look something like this:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Select Query<\/em><\/span><\/p>\n<pre class=\"brush:sql; wrap-lines:false;\">String selectQuery = \"SELECT \" + T1_COL1 + \",\" + T1_COL2 + \",\" + T2_COL1 + \" FROM \" + TABLE1 + \" \" + T1 + \" INNER JOIN \" + TABLE2 + \" \" + T2 + \" ON (\" + T1_IDCOL + \" = \" + T2_IDCOL + \") ORDER BY \" + T1_COL1;\n<\/pre>\n<p>Whenever this query is modified, developers will need to make sure there are sufficient commas, parentheses, spaces to generate the correct query, and the correct columns for the given tables and the correct aliases for those tables.<\/p>\n<p>In this technique matching up the placeholders with the arguments is no simple task and simple rearrangements can easily mess up the resulting query string. Additionally, this is still not a viable solution for any sort of dynamic query generation.<\/p>\n<p>Now, let&#8217;s see how this query looks using <code>SqlBuilder<\/code> classes.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Modified Select Query<\/em><\/span><\/p>\n<pre class=\"brush:sql; wrap-lines:false;\">\/\/ Assuming These Objects Have Already Been Created\nTable table1, table2;\nColumn t1Col1, t1Col2, t2Col1;\nJoin joinOfT1AndT2;\n \nString select_query = (new SelectQuery()).addColumns(t1Col1, t1Col2, t2Col1).addJoin(SelectQuery.JoinType.INNER_JOIN, joinOfT1AndT2).addOrderings(t1Col1).validate().toString();\n<\/pre>\n<p>See how easy that was? Not a single embedded comma, space, or parenthesis to be seen! This is a much more readable version as compared to a previous version.<\/p>\n<p>On top of that, we have a <code>validate()<\/code> method call slipped into the end of the <code>SQL<\/code> statement. This method call will verify that the columns and tables in the query actually make sense. <em>Maintainability<\/em>, <em>readability<\/em>, and <em>verifiability<\/em> all are wrapped into this easy to use package.<\/p>\n<p>As a final <strong>note<\/strong>, the <code>SqlBuilder<\/code> package does not abstract away the knowledge necessary to deal with a database but instead provides tools for avoiding the error-prone parts of generating the <code>SQL<\/code> queries.<\/p>\n<h4>1.3.2 SqlBuilder Features<\/h4>\n<ul>\n<li>Good portion of commonly used <code>SQL<\/code>, including,\n<ul>\n<li><code>SELECT<\/code>, <code>UPDATE<\/code>, <code>DELETE<\/code>, <code>INSERT<\/code>, <code>CREATE<\/code>, <code>DROP<\/code>, <code>UNION<\/code>.<\/li>\n<li>Boolean Logic.<\/li>\n<li>Numeric Expressions.<\/li>\n<\/ul>\n<\/li>\n<li>Supports <a href=\"http:\/\/openhms.sourceforge.net\/sqlbuilder\/apidocs\/com\/healthmarketscience\/sqlbuilder\/Query.html#validate\" target=\"_blank\" rel=\"noopener noreferrer\">Query Validation<\/a> for readability and verifiability.<\/li>\n<li>Helpers for managing <code>PreparedStatement<\/code> parameters (<a href=\"http:\/\/openhms.sourceforge.net\/sqlbuilder\/apidocs\/com\/healthmarketscience\/sqlbuilder\/QueryPreparer.html\" target=\"_blank\" rel=\"noopener noreferrer\">Query Preparer<\/a>) and reading results (<a href=\"http:\/\/openhms.sourceforge.net\/sqlbuilder\/apidocs\/com\/healthmarketscience\/sqlbuilder\/QueryReader.html\" target=\"_blank\" rel=\"noopener noreferrer\">Query Reader<\/a>).<\/li>\n<li><a href=\"http:\/\/openhms.sourceforge.net\/sqlbuilder\/apidocs\/com\/healthmarketscience\/sqlbuilder\/JdbcEscape.html\" target=\"_blank\" rel=\"noopener noreferrer\">JDBC Escape<\/a> syntax support.<\/li>\n<\/ul>\n<h3><a name=\"downloadAndInstallMySQL\"><\/a>1.4 Download and Install MySQL<\/h3>\n<p>In this example, we are using the MySQL database to perform the JDBC Query Builder operations. You can watch <a href=\"https:\/\/www.youtube.com\/watch?v=z1t9m7K6cpI\" target=\"_blank\" rel=\"noopener noreferrer\">this<\/a> video in order to download and install the MySQL database on your Windows operating system.<\/p>\n<p>Now, open up the Eclipse IDE and let\u2019s start building the application!<\/p>\n<h2><a name=\"jdbcQueryBuilderTut\"><\/a>2. JDBC Query Builder Tutorial<\/h2>\n<h3><a name=\"tools\"><\/a>2.1 Tools Used<\/h3>\n<p>We are using Eclipse Kepler SR2, JDK 8, MySQL Database and Maven. Having said that, we have tested the code against JDK 1.7 and it works well.<\/p>\n<h3><a name=\"projectStructure\"><\/a>2.2 Project Structure<\/h3>\n<p>Firstly, let\u2019s review the final project structure, in case you are confused about where you should create the corresponding files or folder later!<\/p>\n<p><figure id=\"attachment_49073\" aria-describedby=\"caption-attachment-49073\" style=\"width: 265px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-application-project-structure.jpg\"><img decoding=\"async\" class=\"size-full wp-image-49073\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-application-project-structure.jpg\" alt=\"Fig. 3: JDBC Query Builder Application Project Structure\" width=\"265\" height=\"433\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-application-project-structure.jpg 265w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-application-project-structure-184x300.jpg 184w\" sizes=\"(max-width: 265px) 100vw, 265px\" \/><\/a><figcaption id=\"caption-attachment-49073\" class=\"wp-caption-text\">Fig. 3: JDBC Query Builder Application Project Structure<\/figcaption><\/figure><div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<h3><a name=\"projectCreation\"><\/a>2.3 Project Creation<\/h3>\n<p>This section will demonstrate on how to create a Java Maven project with Eclipse. In Eclipse IDE, go to <code>File -&gt; New -&gt; Maven Project<\/code>.<\/p>\n<p><figure id=\"attachment_49074\" aria-describedby=\"caption-attachment-49074\" style=\"width: 652px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-example-project-guide-1.jpg\"><img decoding=\"async\" class=\"size-full wp-image-49074\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-example-project-guide-1.jpg\" alt=\"Fig. 4: Create Maven Project\" width=\"652\" height=\"712\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-example-project-guide-1.jpg 652w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-example-project-guide-1-275x300.jpg 275w\" sizes=\"(max-width: 652px) 100vw, 652px\" \/><\/a><figcaption id=\"caption-attachment-49074\" class=\"wp-caption-text\">Fig. 4: Create Maven Project<\/figcaption><\/figure><\/p>\n<p>In the New Maven Project window, it will ask you to select a project location. By default, &#8216;<em>Use default workspace location<\/em>&#8216; will be selected. Select the &#8216;<em>Create a simple project (skip archetype selection)<\/em>&#8216; checkbox and just click on next button to proceed.<\/p>\n<p><figure id=\"attachment_49075\" aria-describedby=\"caption-attachment-49075\" style=\"width: 804px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-example-project-guide-2.jpg\"><img decoding=\"async\" class=\"size-full wp-image-49075\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-example-project-guide-2.jpg\" alt=\"Fig. 5: Project Details\" width=\"804\" height=\"541\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-example-project-guide-2.jpg 804w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-example-project-guide-2-300x202.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-example-project-guide-2-768x517.jpg 768w\" sizes=\"(max-width: 804px) 100vw, 804px\" \/><\/a><figcaption id=\"caption-attachment-49075\" class=\"wp-caption-text\">Fig. 5: Project Details<\/figcaption><\/figure><\/p>\n<p>It will ask you to &#8216;Enter the group and the artifact id for the project.&#8217; We will input the details as shown in the below image. The version number will be by default <code>0.0.1-SNAPSHOT<\/code>.<\/p>\n<p><figure id=\"attachment_49076\" aria-describedby=\"caption-attachment-49076\" style=\"width: 599px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-example-project-guide-3.jpg\"><img decoding=\"async\" class=\"size-full wp-image-49076\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-example-project-guide-3.jpg\" alt=\"Fig. 6: Archetype Parameters\" width=\"599\" height=\"540\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-example-project-guide-3.jpg 599w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-example-project-guide-3-300x270.jpg 300w\" sizes=\"(max-width: 599px) 100vw, 599px\" \/><\/a><figcaption id=\"caption-attachment-49076\" class=\"wp-caption-text\">Fig. 6: Archetype Parameters<\/figcaption><\/figure><\/p>\n<p>Click on Finish and the creation of a maven project will be completed. If you observe, it has downloaded the maven dependencies and a <code>pom.xml<\/code> file will be created. It will have the following code:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>pom.xml<\/em><\/span><\/p>\n<pre class=\"brush:xml; wrap-lines:false;\">&lt;project xmlns=\"http:\/\/maven.apache.org\/POM\/4.0.0\" xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xsi:schemaLocation=\"http:\/\/maven.apache.org\/POM\/4.0.0 http:\/\/maven.apache.org\/xsd\/maven-4.0.0.xsd\"&gt;\n\t&lt;modelVersion&gt;4.0.0&lt;\/modelVersion&gt;\n\t&lt;groupId&gt;JdbcQueryBuilder&lt;\/groupId&gt;\n\t&lt;artifactId&gt;JdbcQueryBuilder&lt;\/artifactId&gt;\n\t&lt;version&gt;0.0.1-SNAPSHOT&lt;\/version&gt;\n&lt;\/project&gt;\n<\/pre>\n<p>We can start adding the dependencies that developers want like MySQL, Log4J, and Sqlbuilder etc. Let\u2019s start building the application!<\/p>\n<h2><a name=\"applicationBuilding\"><\/a>3. Application Building<\/h2>\n<p>Below are the steps involved in developing this application.<\/p>\n<h3><a name=\"dbCreation\"><\/a>3.1 Database<\/h3>\n<p>This tutorial uses a database called <code>tutorialDb<\/code>. The database is not included when you create the project in eclipse so you need to first create the database to follow this tutorial:<\/p>\n<ul>\n<li>Create a new database <code>tutorialDb<\/code> as:<\/li>\n<\/ul>\n<pre class=\"brush:sql; wrap-lines:false;\">CREATE DATABASE IF NOT EXISTS tutorialDb;\n<\/pre>\n<ul>\n<li>Use the created database <code>tutorialDb<\/code> to create table as:<\/li>\n<\/ul>\n<pre class=\"brush:sql; wrap-lines:false;\">USE tutorialDb;\n<\/pre>\n<p>If everything goes well, the database will be shown as below in the MySQL workbench.<\/p>\n<p><figure id=\"attachment_49077\" aria-describedby=\"caption-attachment-49077\" style=\"width: 849px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-application-database-structure.jpg\"><img decoding=\"async\" class=\"size-full wp-image-49077\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-application-database-structure.jpg\" alt=\"Fig. 7: Database Creation\" width=\"849\" height=\"172\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-application-database-structure.jpg 849w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-application-database-structure-300x61.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-application-database-structure-768x156.jpg 768w\" sizes=\"(max-width: 849px) 100vw, 849px\" \/><\/a><figcaption id=\"caption-attachment-49077\" class=\"wp-caption-text\">Fig. 7: Database Creation<\/figcaption><\/figure><\/p>\n<h3><a name=\"mavenJars\"><\/a>3.2 Maven Dependencies<\/h3>\n<p>In this example, we are using the latest MySQL version (i.e. <code>mysql-connector-java-5.1.21<\/code>), Sqlbuilder and Log4J dependencies. The <strong>updated<\/strong> file will have the following code:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>pom.xml<\/em><\/span><\/p>\n<pre class=\"brush:xml; wrap-lines:false;\">&lt;project xmlns=\"http:\/\/maven.apache.org\/POM\/4.0.0\" xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\n\txsi:schemaLocation=\"http:\/\/maven.apache.org\/POM\/4.0.0 http:\/\/maven.apache.org\/xsd\/maven-4.0.0.xsd\"&gt;\n\t&lt;modelVersion&gt;4.0.0&lt;\/modelVersion&gt;\n\t&lt;groupId&gt;JdbcQueryBuilder&lt;\/groupId&gt;\n\t&lt;artifactId&gt;JdbcQueryBuilder&lt;\/artifactId&gt;\n\t&lt;version&gt;0.0.1-SNAPSHOT&lt;\/version&gt;\n\t&lt;packaging&gt;jar&lt;\/packaging&gt;\n\t&lt;dependencies&gt;\n\t\t&lt;dependency&gt;\n\t\t\t&lt;groupId&gt;mysql&lt;\/groupId&gt;\n\t\t\t&lt;artifactId&gt;mysql-connector-java&lt;\/artifactId&gt;\n\t\t\t&lt;version&gt;5.1.21&lt;\/version&gt;\n\t\t&lt;\/dependency&gt;\n\t\t&lt;!-- https:\/\/mvnrepository.com\/artifact\/com.healthmarketscience.sqlbuilder\/sqlbuilder --&gt;\n\t\t&lt;dependency&gt;\n\t\t\t&lt;groupId&gt;com.healthmarketscience.sqlbuilder&lt;\/groupId&gt;\n\t\t\t&lt;artifactId&gt;sqlbuilder&lt;\/artifactId&gt;\n\t\t\t&lt;version&gt;2.1.7&lt;\/version&gt;\n\t\t&lt;\/dependency&gt;\n\t\t&lt;dependency&gt;\n\t\t\t&lt;groupId&gt;log4j&lt;\/groupId&gt;\n\t\t\t&lt;artifactId&gt;log4j&lt;\/artifactId&gt;\n\t\t\t&lt;version&gt;1.2.16&lt;\/version&gt;\n\t\t&lt;\/dependency&gt;\n\t&lt;\/dependencies&gt;\n\t&lt;build&gt;\n\t\t&lt;finalName&gt;${project.artifactId}&lt;\/finalName&gt;\n\t&lt;\/build&gt;\n&lt;\/project&gt;\n<\/pre>\n<h3><a name=\"javaClassCreation\"><\/a>3.3 Java Class Creation<\/h3>\n<p>Let\u2019s create the required Java files. Right click on <code>src\/main\/java<\/code> folder, <code>New -&gt; Package<\/code>.<\/p>\n<p><figure id=\"attachment_49078\" aria-describedby=\"caption-attachment-49078\" style=\"width: 643px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-example-project-guide-4.jpg\"><img decoding=\"async\" class=\"size-full wp-image-49078\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-example-project-guide-4.jpg\" alt=\"Fig. 8: Java Package Creation\" width=\"643\" height=\"658\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-example-project-guide-4.jpg 643w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-example-project-guide-4-293x300.jpg 293w\" sizes=\"(max-width: 643px) 100vw, 643px\" \/><\/a><figcaption id=\"caption-attachment-49078\" class=\"wp-caption-text\">Fig. 8: Java Package Creation<\/figcaption><\/figure><\/p>\n<p>A new pop window will open where we will enter the package name as: <code>com.jcg.jdbc.sql.query.builder<\/code>.<\/p>\n<p><figure id=\"attachment_49079\" aria-describedby=\"caption-attachment-49079\" style=\"width: 518px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-example-project-guide-5.jpg\"><img decoding=\"async\" class=\"size-full wp-image-49079\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-example-project-guide-5.jpg\" alt=\"Fig. 9: Java Package Name (com.jcg.jdbc.sql.query.builder)\" width=\"518\" height=\"473\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-example-project-guide-5.jpg 518w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-example-project-guide-5-300x274.jpg 300w\" sizes=\"(max-width: 518px) 100vw, 518px\" \/><\/a><figcaption id=\"caption-attachment-49079\" class=\"wp-caption-text\">Fig. 9: Java Package Name (com.jcg.jdbc.sql.query.builder)<\/figcaption><\/figure><\/p>\n<p>Once the package is created, we will need to create the database operations and implementation classes. Right click on the newly created package, <code>New -&gt; Class<\/code>.<\/p>\n<p><figure id=\"attachment_49080\" aria-describedby=\"caption-attachment-49080\" style=\"width: 701px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-example-project-guide-6.jpg\"><img decoding=\"async\" class=\"size-full wp-image-49080\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-example-project-guide-6.jpg\" alt=\"Fig. 10: Java Class Creation\" width=\"701\" height=\"658\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-example-project-guide-6.jpg 701w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-example-project-guide-6-300x282.jpg 300w\" sizes=\"(max-width: 701px) 100vw, 701px\" \/><\/a><figcaption id=\"caption-attachment-49080\" class=\"wp-caption-text\">Fig. 10: Java Class Creation<\/figcaption><\/figure><\/p>\n<p>A new pop window will open and enter the file name as: <code>Querybuilder<\/code>. The database operations class will be created inside the package: <code>com.jcg.jdbc.sql.query.builder<\/code>.<\/p>\n<p><figure id=\"attachment_49086\" aria-describedby=\"caption-attachment-49086\" style=\"width: 534px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-example-project-guide-7_copy.jpg\"><img decoding=\"async\" class=\"size-full wp-image-49086\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-example-project-guide-7_copy.jpg\" alt=\"Fig. 11: Java Class (Querybuilder.java)\" width=\"534\" height=\"632\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-example-project-guide-7_copy.jpg 534w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-example-project-guide-7_copy-253x300.jpg 253w\" sizes=\"(max-width: 534px) 100vw, 534px\" \/><\/a><figcaption id=\"caption-attachment-49086\" class=\"wp-caption-text\">Fig. 11: Java Class (Querybuilder.java)<\/figcaption><\/figure><\/p>\n<p>Repeat the step (i.e. Fig. 10) and enter the filename as <code>QueryBuilderDemo<\/code>. The implementation class will be created inside the package: <code>com.jcg.jdbc.sql.query.builder<\/code>.<\/p>\n<p><figure id=\"attachment_49082\" aria-describedby=\"caption-attachment-49082\" style=\"width: 535px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-example-project-guide-8.jpg\"><img decoding=\"async\" class=\"size-full wp-image-49082\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-example-project-guide-8.jpg\" alt=\"Fig. 12: Java Class (QueryBuilderDemo.java)\" width=\"535\" height=\"632\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-example-project-guide-8.jpg 535w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-example-project-guide-8-254x300.jpg 254w\" sizes=\"(max-width: 535px) 100vw, 535px\" \/><\/a><figcaption id=\"caption-attachment-49082\" class=\"wp-caption-text\">Fig. 12: Java Class (QueryBuilderDemo.java)<\/figcaption><\/figure><\/p>\n<h4>3.3.1 Implementation of Db Operations Class<\/h4>\n<p>In JDBC, <code>Connection<\/code> is the session between Java application and database. The Connection interface is a factory of <code>Statement<\/code>, <code>PreparedStatement<\/code>, and <code>DatabaseMetaData<\/code>. This class also contains the code for creating dynamic <code>SQL<\/code> queries with the help of <code>Sqlbuilder<\/code> class. Let&#8217;s see the simple example of query management using <code>Statement<\/code>. Add the following code to it:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Querybuilder.java<\/em><\/span><\/p>\n<pre class=\"brush:java; wrap-lines:false;\">package com.jcg.jdbc.sql.query.builder;\n\nimport java.sql.Connection;\nimport java.sql.DriverManager;\nimport java.sql.ResultSet;\nimport java.sql.Statement;\nimport java.sql.Types;\n\nimport org.apache.log4j.Logger;\n\nimport com.healthmarketscience.sqlbuilder.BinaryCondition;\nimport com.healthmarketscience.sqlbuilder.CreateTableQuery;\nimport com.healthmarketscience.sqlbuilder.DeleteQuery;\nimport com.healthmarketscience.sqlbuilder.DropQuery;\nimport com.healthmarketscience.sqlbuilder.InsertQuery;\nimport com.healthmarketscience.sqlbuilder.SelectQuery;\nimport com.healthmarketscience.sqlbuilder.UpdateQuery;\nimport com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn;\nimport com.healthmarketscience.sqlbuilder.dbspec.basic.DbSchema;\nimport com.healthmarketscience.sqlbuilder.dbspec.basic.DbSpec;\nimport com.healthmarketscience.sqlbuilder.dbspec.basic.DbTable;\n\npublic class Querybuilder implements DbProperties {\n\n\tstatic ResultSet resObj;\n\tstatic Statement stmtObj;\n\tstatic Connection connObj;\n\n\tstatic DbSchema schemaObj;\n\tstatic DbSpec specficationObj;\n\n\tstatic DbTable table_name;\n\tstatic DbColumn column_1, column_2, column_3, column_4;\n\n\tpublic final static Logger logger = Logger.getLogger(Querybuilder.class);\n\n\t\/\/ Helper Method #1 :: This Method Is Used To Create A Connection With The Database\n\tpublic static void connectDb() {\n\t\ttry {\n\t\t\tClass.forName(JDBC_DRIVER);\n\t\t\tconnObj = DriverManager.getConnection(JDBC_DB_URL, JDBC_USER, JDBC_PASS);\n\t\t\tlogger.info(\"\\n=======Database Connection Open=======\\n\");\n\n\t\t\tstmtObj = connObj.createStatement();\n\t\t\tlogger.info(\"\\n=======Statement Object Created=======\\n\");\n\n\t\t\tloadSQLBuilderSchema();\n\t\t} catch(Exception sqlException) {\n\t\t\tsqlException.printStackTrace();\n\t\t}\n\t}\n\n\t\/\/ Helper Method #2 :: This Method Is Used To Create Or Load The Default Schema For The SQLBuilder\n\tprivate static void loadSQLBuilderSchema() {\n\t\tspecficationObj = new DbSpec();\n\t\tschemaObj = specficationObj.addDefaultSchema();\n\t}\n\n\t\/\/ Helper Method #3 :: This Method To Used To Close The Connection With The Database\n\tpublic static void disconnectDb() {\n\t\ttry {\n\t\t\tstmtObj.close();\n\t\t\tconnObj.close();\n\t\t\tlogger.info(\"\\n=======Database Connection Closed=======\\n\");\n\t\t} catch(Exception sqlException) {\n\t\t\tsqlException.printStackTrace();\n\t\t}\n\t}\n\n\t\/\/ SQLQueryBuilder #1 :: This Method Is Used To Perform The Create Operation In The Database\n\tpublic static void createDbTable() {\n\t\tlogger.info(\"\\n=======Creating '\" +TABLE_NAME + \"' In The Database=======\\n\");\n\t\ttry {\n\t\t\t\/\/ Specifying Table Name\n\t\t\ttable_name = schemaObj.addTable(TABLE_NAME);\n\n\t\t\t\/\/ Specifying Column Names For The Table\n\t\t\tcolumn_1 = table_name.addColumn(COLUMN_ONE, Types.INTEGER, 10);\n\t\t\tcolumn_2 = table_name.addColumn(COLUMN_TWO, Types.VARCHAR, 100);\n\t\t\tcolumn_3 = table_name.addColumn(COLUMN_THREE, Types.INTEGER, 200);\n\n\t\t\tString createTableQuery = new CreateTableQuery(table_name, true).validate().toString();\n\t\t\tlogger.info(\"\\nGenerated Sql Query?= \"+ createTableQuery + \"\\n\");\n\t\t\tstmtObj.execute(createTableQuery);\n\t\t} catch(Exception sqlException) {\n\t\t\tsqlException.printStackTrace();\n\t\t}\n\t\tlogger.info(\"\\n=======The '\" + TABLE_NAME + \"' Successfully Created In The Database=======\\n\");\n\t}\n\n\t\/\/ SQLQueryBuilder #2 :: This Method Is Used To Perform The Insert Operation In The Database\n\tpublic static void insertDataInTable(int id, String name, int salary) {\n\t\tString insertTableQuery;\n\t\tlogger.info(\"\\n=======Inserting Record In The '\" + TABLE_NAME + \"'=======\\n\");\n\t\ttry {\n\t\t\tinsertTableQuery = new InsertQuery(table_name).addColumn(column_1, id).addColumn(column_2, name).addColumn(column_3, salary).validate().toString();\n\t\t\tlogger.info(\"\\nGenerated Sql Query?= \"+ insertTableQuery + \"\\n\");\n\t\t\tstmtObj.execute(insertTableQuery);\n\t\t} catch(Exception sqlException) {\n\t\t\tsqlException.printStackTrace();\n\t\t}\n\t\tlogger.info(\"\\n=======Record Sucessfully Inserted  In The '\" + TABLE_NAME + \"'=======\\n\");\n\t}\n\n\t\/\/ SQLQueryBuilder #3 :: This Method Is Used To Display All Records From The Database\n\tpublic static void displayRecords() {\n\t\tString displayRecordsQuery;\n\t\tlogger.info(\"\\n=======Displaying All Records From The '\" + TABLE_NAME + \"'=======\\n\");\n\t\ttry {\n\t\t\tdisplayRecordsQuery = new SelectQuery().addColumns(column_1).addColumns(column_2).addColumns(column_3).validate().toString();\n\t\t\tlogger.info(\"\\nGenerated Sql Query?= \"+ displayRecordsQuery + \"\\n\");\n\n\t\t\tresObj = stmtObj.executeQuery(displayRecordsQuery);\n\t\t\tif(!resObj.next()) {\n\t\t\t\tlogger.info(\"\\n=======No Records Are Present In The '\" + TABLE_NAME + \"'=======\\n\");\n\t\t\t} else {\n\t\t\t\tdo {\n\t\t\t\t\tlogger.info(\"\\nId?= \" + resObj.getString(COLUMN_ONE) + \", Name?= \" + resObj.getString(COLUMN_TWO) + \", Salary?= \" + resObj.getString(COLUMN_THREE) + \"\\n\");\n\t\t\t\t} while (resObj.next());\n\t\t\t\tlogger.info(\"\\n=======All Records Displayed From The '\" + TABLE_NAME + \"'=======\\n\");\n\t\t\t}\n\t\t} catch(Exception sqlException) {\n\t\t\tsqlException.printStackTrace();\n\t\t}\n\t}\n\n\t\/\/ SQLQueryBuilder #4 :: This Method Is Used To Display A Specific Record From The Database\n\tpublic static void displaySelectiveRecord(int emp_id) {\n\t\tString selectiveRecordQuery;\n\t\tlogger.info(\"\\n=======Displaying Specific Record From The '\" + TABLE_NAME + \"'=======\\n\");\n\t\ttry {\n\t\t\tselectiveRecordQuery = new SelectQuery().addColumns(column_1).addColumns(column_2).addColumns(column_3).addCondition(BinaryCondition.equalTo(column_1, emp_id)).validate().toString();\n\t\t\tlogger.info(\"\\nGenerated Sql Query?= \"+ selectiveRecordQuery + \"\\n\");\n\n\t\t\tresObj = stmtObj.executeQuery(selectiveRecordQuery);\n\t\t\tif(!resObj.next()) {\n\t\t\t\tlogger.info(\"\\n=======No Record Is Present In The '\" + TABLE_NAME + \"'=======\\n\");\n\t\t\t} else {\n\t\t\t\tdo {\n\t\t\t\t\tlogger.info(\"\\nId?= \" + resObj.getString(COLUMN_ONE) + \", Name?= \" + resObj.getString(COLUMN_TWO) + \", Salary?= \" + resObj.getString(COLUMN_THREE) + \"\\n\");\n\t\t\t\t} while (resObj.next());\n\t\t\t}\n\t\t} catch(Exception sqlException) {\n\t\t\tsqlException.printStackTrace();\n\t\t}\n\t\tlogger.info(\"\\n=======Specific Record Displayed From The '\" + TABLE_NAME + \"'=======\\n\");\n\t}\n\n\t\/\/ SQLQueryBuilder #5 :: This Method Is Used To Update A Record In The Database\n\tpublic static void updateRecord(int update_record_id) {\n\t\tString updateRecord, editorName = \"Java Code Geek\";\n\t\tlogger.info(\"\\n=======Updating Record In The '\" + TABLE_NAME + \"'=======\\n\");\n\t\ttry {\n\t\t\tupdateRecord = new UpdateQuery(table_name).addSetClause(column_2, editorName).addCondition(BinaryCondition.equalTo(column_1, update_record_id)).validate().toString();\n\t\t\tlogger.info(\"\\nGenerated Sql Query?= \"+ updateRecord + \"\\n\");\n\t\t\tstmtObj.execute(updateRecord);\n\t\t} catch(Exception sqlException) {\n\t\t\tsqlException.printStackTrace();\n\t\t}\n\t\tlogger.info(\"\\n=======Record Updated In The '\" + TABLE_NAME + \"' =======\\n\");\n\t}\n\n\t\/\/ SQLQueryBuilder #6 :: This Method Is Used To Delete A Specific Record From The Table\n\tpublic static void deleteSelectiveRecord(int delete_record_id) {\n\t\tString deleteSelectiveRecordQuery;\n\t\tlogger.info(\"\\n=======Deleting Specific Record From The '\" + TABLE_NAME + \"'=======\\n\");\n\t\ttry {\n\t\t\tdeleteSelectiveRecordQuery = new DeleteQuery(table_name).addCondition(BinaryCondition.equalTo(column_1, delete_record_id)).validate().toString();\n\t\t\tlogger.info(\"\\nGenerated Sql Query?= \"+ deleteSelectiveRecordQuery + \"\\n\");\n\t\t\tstmtObj.execute(deleteSelectiveRecordQuery);\n\t\t} catch(Exception sqlException) {\n\t\t\tsqlException.printStackTrace();\n\t\t}\n\t\tlogger.info(\"\\n=======Selective Specific Deleted From The '\" + TABLE_NAME + \"'=======\\n\");\n\t}\n\n\t\/\/ SQLQueryBuilder #7 :: This Method Is Used To Delete All Records From The Table\n\tpublic static void deleteRecords() {\n\t\tString deleteRecordsQuery;\n\t\tlogger.info(\"\\n=======Deleting All Records From The '\" + TABLE_NAME + \"'=======\\n\");\n\t\ttry {\n\t\t\tdeleteRecordsQuery = new DeleteQuery(table_name).validate().toString();\n\t\t\tlogger.info(\"\\nGenerated Sql Query?= \"+ deleteRecordsQuery + \"\\n\");\n\t\t\tstmtObj.execute(deleteRecordsQuery);\n\t\t} catch(Exception sqlException) {\n\t\t\tsqlException.printStackTrace();\n\t\t}\n\t\tlogger.info(\"\\n=======All Records Deleted From The '\" + TABLE_NAME + \"'=======\\n\");\n\t}\n\n\t\/\/ SQLQueryBuilder #8 :: This Method Is Used To Drop A Table From The Database\n\t@SuppressWarnings(\"static-access\")\n\tpublic static void dropTableFromDb() {\n\t\tString dropTableQuery;\n\t\tlogger.info(\"\\n=======Dropping '\" + TABLE_NAME + \"' From The Database=======\\n\");\n\t\ttry {\n\t\t\tdropTableQuery = new DropQuery(DropQuery.Type.TABLE, table_name).dropTable(table_name).validate().toString();\n\t\t\tlogger.info(\"\\nGenerated Sql Query?= \"+ dropTableQuery + \"\\n\");\n\t\t\tstmtObj.execute(dropTableQuery);\n\t\t} catch(Exception sqlException) {\n\t\t\tsqlException.printStackTrace();\n\t\t}\n\t\tlogger.info(\"\\n======='\" + TABLE_NAME + \"' Is Dropped From The Database=======\\n\");\n\t}\n}\n<\/pre>\n<h4>3.3.2 Implementation of Main Class<\/h4>\n<p>In this class, we will be establishing a connection to the database using JDBC API and will be performing the <code>Sqlbuilder<\/code> operations for performing the <code>SQL<\/code> transactions.[ulp id=&#8217;TD36VgQCKfhTAygK&#8217;]<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Querybuilder.java<\/em><\/span><\/p>\n<pre class=\"brush:java; wrap-lines:false;\">package com.jcg.jdbc.sql.query.builder;\n\nimport java.util.Random;\n\npublic class QueryBuilderDemo {\n\n\tpublic static void main(String[] args) {\n\n\t\t\/\/ Method #1 :: This Method Is Used To Connect With The Database\n\t\tQuerybuilder.connectDb();\n\n\t\t\/\/ Method #2 :: This Method Is Used To Create A Database Table Using SQLQueryBuilder Utility\n\t\tQuerybuilder.createDbTable();\n\n\t\t\/\/ Method #3 :: This Method Is Used To Insert Records In A Table Using SQLQueryBuilder Utility\n\t\tfor(int count = 101; count &lt; 106; count++) {\n\t\t\tint randomSalary = 1000 + new Random().nextInt(500);\n\t\t\tQuerybuilder.insertDataInTable(count, \"Editor\" + count, randomSalary);\n\t\t}\n\n\t\t\/\/  Method #4 :: This Method Is Used To Display All Records From The Table Using SQLQueryBuilder Utility\n\t\tQuerybuilder.displayRecords();\n\n\t\t\/\/ Method #5 :: This Method Is Used To Display A Specific Record From The Table Using SQLQueryBuilder Utility\n\t\tQuerybuilder.displaySelectiveRecord(103);\n\n\t\t\/\/ Method #6 :: This Method Is Used To Update A Record In A Table Using SQLQueryBuilder Utility\n\t\tQuerybuilder.updateRecord(101);\n\n\t\t\/\/ Method #7 :: This Method Is Used To Delete A Specific Record From The Table Using SQLQueryBuilder Utility\n\t\tQuerybuilder.deleteSelectiveRecord(103);\n\n\t\tQuerybuilder.displayRecords();\n\n\t\t\/\/ Method #8 :: This Method Is Used To Delete All Records From The Table Using SQLQueryBuilder Utility\n\t\tQuerybuilder.deleteRecords();\n\n\t\tQuerybuilder.displayRecords();\n\n\t\t\/\/ Method #9 :: This Method Is Used To Drop A Table From The Database Using SQLQueryBuilder Utility\n\t\tQuerybuilder.dropTableFromDb();\n\n\t\t\/\/ Method #10 :: This Method Is Used To Disconnect From The Database Using SQLQueryBuilder Utility\n\t\tQuerybuilder.disconnectDb();\n\t}\n}\n<\/pre>\n<h2><a name=\"projectRun\"><\/a>4. Run the Application<\/h2>\n<p>To run the application, Right click on the <code>QueryBuilderDemo<\/code> class, <code>Run As -&gt; Java Application<\/code>.<\/p>\n<p><figure id=\"attachment_49088\" aria-describedby=\"caption-attachment-49088\" style=\"width: 832px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-application-project-deploy-1.jpg\"><img decoding=\"async\" class=\"size-full wp-image-49088\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-application-project-deploy-1.jpg\" alt=\"Fig. 13: Run Application\" width=\"832\" height=\"694\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-application-project-deploy-1.jpg 832w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-application-project-deploy-1-300x250.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-application-project-deploy-1-768x641.jpg 768w\" sizes=\"(max-width: 832px) 100vw, 832px\" \/><\/a><figcaption id=\"caption-attachment-49088\" class=\"wp-caption-text\">Fig. 13: Run Application<\/figcaption><\/figure><\/p>\n<h2><a name=\"projectDemo\"><\/a>5. Project Demo<\/h2>\n<p>The code shows the following status as output.<\/p>\n<ul>\n<li><span style=\"text-decoration: underline;\">Create Query<\/span><\/li>\n<\/ul>\n<p><figure id=\"attachment_49090\" aria-describedby=\"caption-attachment-49090\" style=\"width: 848px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-application-database-project-demo-1.jpg\"><img decoding=\"async\" class=\"size-full wp-image-49090\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-application-database-project-demo-1.jpg\" alt=\"Fig. 14: Creating Table in the Database\" width=\"848\" height=\"160\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-application-database-project-demo-1.jpg 848w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-application-database-project-demo-1-300x57.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-application-database-project-demo-1-768x145.jpg 768w\" sizes=\"(max-width: 848px) 100vw, 848px\" \/><\/a><figcaption id=\"caption-attachment-49090\" class=\"wp-caption-text\">Fig. 14: Creating Table in the Database<\/figcaption><\/figure><\/p>\n<ul>\n<li><span style=\"text-decoration: underline;\">Insert Query<\/span><\/li>\n<\/ul>\n<p><figure id=\"attachment_49091\" aria-describedby=\"caption-attachment-49091\" style=\"width: 849px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-application-database-project-demo-2.jpg\"><img decoding=\"async\" class=\"size-full wp-image-49091\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-application-database-project-demo-2.jpg\" alt=\"Fig. 15: Inserting Records in the Table\" width=\"849\" height=\"460\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-application-database-project-demo-2.jpg 849w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-application-database-project-demo-2-300x163.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-application-database-project-demo-2-768x416.jpg 768w\" sizes=\"(max-width: 849px) 100vw, 849px\" \/><\/a><figcaption id=\"caption-attachment-49091\" class=\"wp-caption-text\">Fig. 15: Inserting Records in the Table<\/figcaption><\/figure><\/p>\n<ul>\n<li><span style=\"text-decoration: underline;\">Select Query<\/span><\/li>\n<\/ul>\n<p><figure id=\"attachment_49092\" aria-describedby=\"caption-attachment-49092\" style=\"width: 849px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-application-database-project-demo-3.jpg\"><img decoding=\"async\" class=\"size-full wp-image-49092\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-application-database-project-demo-3.jpg\" alt=\"Fig. 15: Displaying All Records\" width=\"849\" height=\"247\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-application-database-project-demo-3.jpg 849w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-application-database-project-demo-3-300x87.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-application-database-project-demo-3-768x223.jpg 768w\" sizes=\"(max-width: 849px) 100vw, 849px\" \/><\/a><figcaption id=\"caption-attachment-49092\" class=\"wp-caption-text\">Fig. 15: Displaying All Records<\/figcaption><\/figure><\/p>\n<p>&nbsp;<\/p>\n<p><figure id=\"attachment_49094\" aria-describedby=\"caption-attachment-49094\" style=\"width: 849px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-application-database-project-demo-4.jpg\"><img decoding=\"async\" class=\"size-full wp-image-49094\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-application-database-project-demo-4.jpg\" alt=\"Fig. 16: Displaying Specific Record\" width=\"849\" height=\"123\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-application-database-project-demo-4.jpg 849w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-application-database-project-demo-4-300x43.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-application-database-project-demo-4-768x111.jpg 768w\" sizes=\"(max-width: 849px) 100vw, 849px\" \/><\/a><figcaption id=\"caption-attachment-49094\" class=\"wp-caption-text\">Fig. 16: Displaying Specific Record<\/figcaption><\/figure><\/p>\n<ul>\n<li><span style=\"text-decoration: underline;\">Update SQL Query<\/span><\/li>\n<\/ul>\n<p><figure id=\"attachment_49095\" aria-describedby=\"caption-attachment-49095\" style=\"width: 849px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-application-database-project-demo-5.jpg\"><img decoding=\"async\" class=\"size-full wp-image-49095\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-application-database-project-demo-5.jpg\" alt=\"Fig. 17: Updating Record for Employee Id \u2013 103\" width=\"849\" height=\"89\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-application-database-project-demo-5.jpg 849w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-application-database-project-demo-5-300x31.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-application-database-project-demo-5-768x81.jpg 768w\" sizes=\"(max-width: 849px) 100vw, 849px\" \/><\/a><figcaption id=\"caption-attachment-49095\" class=\"wp-caption-text\">Fig. 17: Updating Record for Employee Id \u2013 103<\/figcaption><\/figure><\/p>\n<ul>\n<li><span style=\"text-decoration: underline;\">Delete SQL Query<\/span><\/li>\n<\/ul>\n<p><figure id=\"attachment_49096\" aria-describedby=\"caption-attachment-49096\" style=\"width: 849px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-application-database-project-demo-6.jpg\"><img decoding=\"async\" class=\"size-full wp-image-49096\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-application-database-project-demo-6.jpg\" alt=\"Fig. 18: Delete Record for Employee Id \u2013 101\" width=\"849\" height=\"95\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-application-database-project-demo-6.jpg 849w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-application-database-project-demo-6-300x34.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-application-database-project-demo-6-768x86.jpg 768w\" sizes=\"(max-width: 849px) 100vw, 849px\" \/><\/a><figcaption id=\"caption-attachment-49096\" class=\"wp-caption-text\">Fig. 18: Delete Record for Employee Id \u2013 101<\/figcaption><\/figure><\/p>\n<p>&nbsp;<\/p>\n<p><figure id=\"attachment_49097\" aria-describedby=\"caption-attachment-49097\" style=\"width: 849px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-application-database-project-demo-7.jpg\"><img decoding=\"async\" class=\"size-full wp-image-49097\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-application-database-project-demo-7.jpg\" alt=\"Fig. 19: Displaying All Records\" width=\"849\" height=\"216\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-application-database-project-demo-7.jpg 849w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-application-database-project-demo-7-300x76.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-application-database-project-demo-7-768x195.jpg 768w\" sizes=\"(max-width: 849px) 100vw, 849px\" \/><\/a><figcaption id=\"caption-attachment-49097\" class=\"wp-caption-text\">Fig. 19: Displaying All Records<\/figcaption><\/figure><\/p>\n<ul>\n<li><span style=\"text-decoration: underline;\">Drop SQL Query<\/span><\/li>\n<\/ul>\n<p><figure id=\"attachment_49098\" aria-describedby=\"caption-attachment-49098\" style=\"width: 849px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-application-database-project-demo-9.jpg\"><img decoding=\"async\" class=\"size-full wp-image-49098\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-application-database-project-demo-9.jpg\" alt=\"Fig. 20: Dropping Table from the Database\" width=\"849\" height=\"120\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-application-database-project-demo-9.jpg 849w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-application-database-project-demo-9-300x42.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/jdbc-querybuilder-application-database-project-demo-9-768x109.jpg 768w\" sizes=\"(max-width: 849px) 100vw, 849px\" \/><\/a><figcaption id=\"caption-attachment-49098\" class=\"wp-caption-text\">Fig. 20: Dropping Table from the Database<\/figcaption><\/figure><\/p>\n<p>That\u2019s all for this post. Happy Learning!!<\/p>\n<h2><a name=\"projectConclusion\"><\/a>6. Conclusion<\/h2>\n<p>Here, in this example we tried to understand JDBC Operations through dynamic SQL queries and how to can consume the <code>Sqlbuilder<\/code> library for maintaining readability and verifiability.<\/p>\n<h2><a name=\"projectDownload\"><\/a>7. Download the Eclipse Project<\/h2>\n<p>This was an example of JBDC Query Builder Example.<\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here: <a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/Jdbc-QueryBuilder.zip\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>Jdbc QueryBuilder<\/strong><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Handling SQL within a Java application can be tricky. For one thing, Java does not support multi-line string constants, so developers can end up with code that looks like this: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Sample Code String sql_query = &#8220;select *&#8221; + &#8220;from user_table&#8221; + &#8220;where name like &#8216;Fred%'&#8221;; &hellip;<\/p>\n","protected":false},"author":119,"featured_media":1204,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[53],"tags":[216,647,701],"class_list":["post-49070","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-sql","tag-jdbc-2","tag-mysql","tag-query"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>JDBC Query Builder Tutorial - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"In this JDBC Query Builder example, we will see how to achieve dynamic SQL Query Builder phenomenon by using the open-source Sqlbuilder library\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/jdbc-query-builder-tutorial\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"JDBC Query Builder Tutorial - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"In this JDBC Query Builder example, we will see how to achieve dynamic SQL Query Builder phenomenon by using the open-source Sqlbuilder library\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/jdbc-query-builder-tutorial\/\" \/>\n<meta property=\"og:site_name\" content=\"Examples Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2017-08-08T08:00:01+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-03-05T11:01:50+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Yatin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Yatin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"17 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/jdbc-query-builder-tutorial\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/jdbc-query-builder-tutorial\/\"},\"author\":{\"name\":\"Yatin\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/9874407a37b028e8be3276e2b5960d13\"},\"headline\":\"JDBC Query Builder Tutorial\",\"datePublished\":\"2017-08-08T08:00:01+00:00\",\"dateModified\":\"2019-03-05T11:01:50+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/jdbc-query-builder-tutorial\/\"},\"wordCount\":1739,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/jdbc-query-builder-tutorial\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"keywords\":[\"jdbc\",\"mysql\",\"query\"],\"articleSection\":[\"sql\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/jdbc-query-builder-tutorial\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/jdbc-query-builder-tutorial\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/jdbc-query-builder-tutorial\/\",\"name\":\"JDBC Query Builder Tutorial - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/jdbc-query-builder-tutorial\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/jdbc-query-builder-tutorial\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"datePublished\":\"2017-08-08T08:00:01+00:00\",\"dateModified\":\"2019-03-05T11:01:50+00:00\",\"description\":\"In this JDBC Query Builder example, we will see how to achieve dynamic SQL Query Builder phenomenon by using the open-source Sqlbuilder library\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/jdbc-query-builder-tutorial\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/jdbc-query-builder-tutorial\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/jdbc-query-builder-tutorial\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"width\":150,\"height\":150,\"caption\":\"Bipartite Graph\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/jdbc-query-builder-tutorial\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/examples.javacodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java Development\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Core Java\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"sql\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/sql\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"JDBC Query Builder Tutorial\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Examples and Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/javacodegeeks\",\"https:\/\/x.com\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/9874407a37b028e8be3276e2b5960d13\",\"name\":\"Yatin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2023\/09\/cropped-Yatin-Batra_avatar_1515758148-96x96.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2023\/09\/cropped-Yatin-Batra_avatar_1515758148-96x96.jpg\",\"caption\":\"Yatin\"},\"description\":\"An experience full-stack engineer well versed with Core Java, Spring\/Springboot, MVC, Security, AOP, Frontend (Angular &amp; React), and cloud technologies (such as AWS, GCP, Jenkins, Docker, K8).\",\"sameAs\":[\"https:\/\/www.javacodegeeks.com\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/yatin-batra\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"JDBC Query Builder Tutorial - Java Code Geeks","description":"In this JDBC Query Builder example, we will see how to achieve dynamic SQL Query Builder phenomenon by using the open-source Sqlbuilder library","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/jdbc-query-builder-tutorial\/","og_locale":"en_US","og_type":"article","og_title":"JDBC Query Builder Tutorial - Java Code Geeks","og_description":"In this JDBC Query Builder example, we will see how to achieve dynamic SQL Query Builder phenomenon by using the open-source Sqlbuilder library","og_url":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/jdbc-query-builder-tutorial\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2017-08-08T08:00:01+00:00","article_modified_time":"2019-03-05T11:01:50+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","type":"image\/jpeg"}],"author":"Yatin","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Yatin","Est. reading time":"17 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/jdbc-query-builder-tutorial\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/jdbc-query-builder-tutorial\/"},"author":{"name":"Yatin","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/9874407a37b028e8be3276e2b5960d13"},"headline":"JDBC Query Builder Tutorial","datePublished":"2017-08-08T08:00:01+00:00","dateModified":"2019-03-05T11:01:50+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/jdbc-query-builder-tutorial\/"},"wordCount":1739,"commentCount":2,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/jdbc-query-builder-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","keywords":["jdbc","mysql","query"],"articleSection":["sql"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/jdbc-query-builder-tutorial\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/jdbc-query-builder-tutorial\/","url":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/jdbc-query-builder-tutorial\/","name":"JDBC Query Builder Tutorial - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/jdbc-query-builder-tutorial\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/jdbc-query-builder-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","datePublished":"2017-08-08T08:00:01+00:00","dateModified":"2019-03-05T11:01:50+00:00","description":"In this JDBC Query Builder example, we will see how to achieve dynamic SQL Query Builder phenomenon by using the open-source Sqlbuilder library","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/jdbc-query-builder-tutorial\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/jdbc-query-builder-tutorial\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/jdbc-query-builder-tutorial\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","width":150,"height":150,"caption":"Bipartite Graph"},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/jdbc-query-builder-tutorial\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/examples.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java Development","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/"},{"@type":"ListItem","position":3,"name":"Core Java","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/"},{"@type":"ListItem","position":4,"name":"sql","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/sql\/"},{"@type":"ListItem","position":5,"name":"JDBC Query Builder Tutorial"}]},{"@type":"WebSite","@id":"https:\/\/examples.javacodegeeks.com\/#website","url":"https:\/\/examples.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/examples.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/examples.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/9874407a37b028e8be3276e2b5960d13","name":"Yatin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2023\/09\/cropped-Yatin-Batra_avatar_1515758148-96x96.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2023\/09\/cropped-Yatin-Batra_avatar_1515758148-96x96.jpg","caption":"Yatin"},"description":"An experience full-stack engineer well versed with Core Java, Spring\/Springboot, MVC, Security, AOP, Frontend (Angular &amp; React), and cloud technologies (such as AWS, GCP, Jenkins, Docker, K8).","sameAs":["https:\/\/www.javacodegeeks.com"],"url":"https:\/\/examples.javacodegeeks.com\/author\/yatin-batra\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/49070","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/users\/119"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=49070"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/49070\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/1204"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=49070"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=49070"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=49070"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}