{"id":16377105,"url":"https://github.com/danfickle/java-sql-query-builder","last_synced_at":"2025-03-23T03:32:48.259Z","repository":{"id":3483566,"uuid":"4539150","full_name":"danfickle/java-sql-query-builder","owner":"danfickle","description":"A Java SQL query builder based loosely on the query builder included with the CodeIgniter framework.","archived":false,"fork":false,"pushed_at":"2012-06-05T07:55:34.000Z","size":156,"stargazers_count":18,"open_issues_count":0,"forks_count":11,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-18T17:14:22.304Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/danfickle.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-06-03T17:38:29.000Z","updated_at":"2025-02-17T19:07:33.000Z","dependencies_parsed_at":"2022-09-04T03:12:02.542Z","dependency_job_id":null,"html_url":"https://github.com/danfickle/java-sql-query-builder","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danfickle%2Fjava-sql-query-builder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danfickle%2Fjava-sql-query-builder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danfickle%2Fjava-sql-query-builder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danfickle%2Fjava-sql-query-builder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danfickle","download_url":"https://codeload.github.com/danfickle/java-sql-query-builder/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245052634,"owners_count":20553162,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-11T03:28:42.066Z","updated_at":"2025-03-23T03:32:47.878Z","avatar_url":"https://github.com/danfickle.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Java SQL Query Builder #\n\nThis project is an SQL query builder for Java. Currently it only supports MySql. However, it programs to interfaces so should be easy to add other SQL dialects.\n\nThe project is licensed under the permissive BSD license.\n\nThis is a sample of using this project to generate queries:\n\n\t/**\n\t * Sample of using java-sql-query-builder with various queries.\n\t * IMPORTANT:\n\t *   For clarity exception handling and cleanup is left out.\n\t */\n\tstatic void sample() throws SQLException, ClassNotFoundException\n\t{\n\t\tClass.forName(\"com.mysql.jdbc.Driver\");\n\t\tConnection conn = DriverManager.getConnection(\"jdbc:mysql://localhost:3306/YourDatabase\", \"root\", \"your_password\");\t\t\n\t\tPreparedStatement stmt;\n\t\t\n\t\tQbFactory f = new QbFactoryImp();\n\n\t\t// Update first_name, last_name and age for a given id...\n\t\tQbUpdate up = f.newUpdateQuery();\n\t\tup.set(f.newStdField(\"first_name\"), \":first_name\")\n\t\t  .set(f.newStdField(\"last_name\"), \":last_name\")\n\t\t  .set(f.newStdField(\"age\"), \":age\")\n\t\t  .inTable(\"myTable\")\n\t\t  .where()\n\t\t  .where(f.newStdField(\"id\"), \":id\");\n\t\tstmt = conn.prepareStatement(up.getQueryString());\n\t\tstmt.setString(up.getPlaceholderIndex(\":first_name\"), \"John\");\n\t\tstmt.setString(up.getPlaceholderIndex(\":last_name\"), \"Citizen\");\n\t\tstmt.setInt(up.getPlaceholderIndex(\":age\"), 32);\n\t\tstmt.setInt(up.getPlaceholderIndex(\":id\"), 1024);\n\t\tstmt.executeUpdate();\n\t\t\n\t\t// Delete all records with a given age value...\n\t\tQbDelete del = f.newDeleteQuery();\n\t\tdel.from(\"myTable\")\n\t\t   .where()\n\t\t   .where(f.newStdField(\"age\"), \":age\");\n\t\tstmt = conn.prepareStatement(del.getQueryString());\n\t\tstmt.setInt(del.getPlaceholderIndex(\":age\"), 32);\n\t\tstmt.executeUpdate();\n\t\t\n\t\t// Insert a record with the egg_hatched field set to true...\n\t\tQbInsert in = f.newInsertQuery();\n\t\tin.set(f.newStdField(\"egg_hatched\"), \":egg_hatched\")\n\t\t  .inTable(\"myTable\");\n\t\tstmt = conn.prepareStatement(in.getQueryString());\n\t\tstmt.setBoolean(in.getPlaceholderIndex(\":egg_hatched\"), true);\n\t\tstmt.executeUpdate();\n\t\t\n\t\t// Simple select query, retrieves id, age and last_name for records which\n\t\t// don't have the given id...\n\t\tQbSelect sel = f.newSelectQuery();\n\t\tsel.select(f.newStdField(\"id\"), f.newStdField(\"age\"), f.newStdField(\"last_name\"))\n\t\t   .from(\"myTable\")\n\t\t   .where()\n\t\t   .where(f.newStdField(\"id\"), QbWhereOperator.NOT_EQUALS, \":id\");\n\t\tstmt = conn.prepareStatement(sel.getQueryString());\n\t\tstmt.setInt(sel.getPlaceholderIndex(\":id\"), 1024);\n\t\tResultSet rs = stmt.executeQuery();\n\t\t\n\t\twhile (rs.next())\n\t\t{\n\t\t\tSystem.out.println(rs.getInt(\"id\") + \":\" + rs.getInt(\"age\") + \":\" + rs.getString(\"last_name\"));\n\t\t}\n\t\t\n\t\t// Complicated select query with join...\n\t\tsel = f.newSelectQuery();\n\t\tsel.select(f.newQualifiedField(\"t1\", \"id\"), f.newQualifiedField(\"t2\", \"id\"))\n\t\t   .from(\"t1\")\n\t\t   .join(\"t2\", f.newQualifiedField(\"t2\", \"id\"), f.newQualifiedField(\"t1\", \"t1_id\"), QbJoinType.LEFT)\n\t\t   .where()\n\t\t   .where(f.newStdField(\"age\"), \":age\");\n\t\tstmt = conn.prepareStatement(sel.getQueryString());\n\t\tstmt.setInt(sel.getPlaceholderIndex(\":age\"), 45);\n\t\trs = stmt.executeQuery();\n\t\t// Record enumeration left out...\n\t\t\n\t\t\n\t\t// Select query with group by...\n\t\tsel = f.newSelectQuery();\n\t\tsel.select(f.newAvg(f.newStdField(\"age\"), \"avg_age\"))\n\t\t   .from(\"myTable\")\n\t\t   .groupBy(f.newStdField(\"first_name\"))\n\t\t   .having()\n\t\t   .where(f.newStdField(\"avg_age\"), QbWhereOperator.GREATER_THAN, \":avg_age\");\n\t\tstmt = conn.prepareStatement(sel.getQueryString());\n\t\tstmt.setInt(sel.getPlaceholderIndex(\":avg_age\"), 50);\n\t\trs = stmt.executeQuery();\n\t\t// Record enumeration left out...\n\t}\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanfickle%2Fjava-sql-query-builder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanfickle%2Fjava-sql-query-builder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanfickle%2Fjava-sql-query-builder/lists"}