{"id":30039678,"url":"https://github.com/manticore-projects/mjdbcutils","last_synced_at":"2025-08-07T01:48:50.171Z","repository":{"id":130375631,"uuid":"453358512","full_name":"manticore-projects/MJdbcUtils","owner":"manticore-projects","description":"Java Library supporting Named Parameters (e.g. :Customer_Id ) in Queries or DML/DDL statements.","archived":false,"fork":false,"pushed_at":"2025-05-20T08:12:17.000Z","size":318,"stargazers_count":6,"open_issues_count":2,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-20T09:27:37.075Z","etag":null,"topics":["h2","jdbc","named","oracle","parameter","pivot"],"latest_commit_sha":null,"homepage":"https://manticore-projects.com/MJdbcUtils/index.html","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/manticore-projects.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-01-29T09:54:44.000Z","updated_at":"2025-05-20T08:11:41.000Z","dependencies_parsed_at":"2023-12-12T15:27:24.612Z","dependency_job_id":"6f31120b-b34b-4fc2-a955-27e7bf593701","html_url":"https://github.com/manticore-projects/MJdbcUtils","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/manticore-projects/MJdbcUtils","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manticore-projects%2FMJdbcUtils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manticore-projects%2FMJdbcUtils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manticore-projects%2FMJdbcUtils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manticore-projects%2FMJdbcUtils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/manticore-projects","download_url":"https://codeload.github.com/manticore-projects/MJdbcUtils/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manticore-projects%2FMJdbcUtils/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269185780,"owners_count":24374632,"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","status":"online","status_checked_at":"2025-08-06T02:00:09.910Z","response_time":99,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["h2","jdbc","named","oracle","parameter","pivot"],"created_at":"2025-08-07T01:48:45.803Z","updated_at":"2025-08-07T01:48:50.153Z","avatar_url":"https://github.com/manticore-projects.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MJdbcUtils [WebSite](http://manticore-projects.com/MJdbcUtils/README.html)\n\n![Maven](https://badgen.net/maven/v/maven-central/com.manticore-projects.jdbc/MJdbcUtils) [![Codacy Badge](https://app.codacy.com/project/badge/Grade/e3295140a0b841f3be25da37ff8d4756)](https://app.codacy.com/gh/manticore-projects/MJdbcUtils/dashboard?utm_source=gh\u0026utm_medium=referral\u0026utm_content=\u0026utm_campaign=Badge_grade) [![Coverage Status](https://coveralls.io/repos/github/manticore-projects/MJdbcUtils/badge.svg?branch=main)](https://coveralls.io/github/manticore-projects/MJdbcUtils?branch=main) [![License](https://img.shields.io/badge/License-GPL-blue)](#license)\n[![issues - MJdbcUtils](https://img.shields.io/github/issues/manticore-projects/MJdbcUtils)](https://github.com/manticore-projects/MJdbcUtils/issues)\n\nLibrary supporting Named Parameters (e.g. `:Customer_Id` ) in Queries or DML/DDL statements.\n\n[GitHub](https://github.com/manticore-projects/MJdbcUtils) [WebSite](http://manticore-projects.com/MJdbcUtils/README.html)\n\n## Use case\nWhen the RDBMS does not support Named Parameters directly, it will:\n\n1) find any Named Parameter,\n\n2) replace it with an ordinary Positional Parameter `?`,\n\n3) maintain a map between the Position and the Named Parameter\n\n4) provide methods for applying the Parameter Values and retrieving Parameter Type information.\n\nIt supports PreparedStatements with parameters and also rewriting/injecting SQL Statements for execution without parameters.\nRewriting/injecting is useful for Oracle Databases, which do not allow parameters for DDL Statements (not even for the query block of `CTAS`).\n\nFurthermore, **MJdbcUtils** makes it easy to build an UI Parameter Dialog based on the used Parameters and the Type Information.\n\n## Examples\n\nBased on a Table Definition\n\n```sql\nCREATE TABLE test (\n    a DECIMAL(3) PRIMARY KEY\n    , b VARCHAR(128) NOT NULL\n    , c DATE NOT NULL\n    , d TIMESTAMP NOT NULL\n    , e DECIMAL(23,5) NOT NULL\n    )\n```\n\n1) We can fill the table with a simple update\n\n    ```java\n    // DML statement with Named Parameters\n    String dmlStr = \"INSERT INTO test VALUES ( :a, :b, :c, :d, :e )\";\n\n    // Helper function will fill our parameter map with values\n    Map\u003cString, Object\u003e parameters = toMap(\"a\", 1, \"b\", \"Test String\", \"c\", new Date(), \"d\", new Date(), \"e\", \"0.12345\");\n\n    // Create a Prepared Statement, which holds our parameter mapping\n    MPreparedStatement st = new MPreparedStatement(conn, dmlStr);\n\n    // Execute our statement with the provided parameter values\n    Assertions.assertFalse( st.execute(parameters) );\n    ```\n\n2) We can fill table using Batch Updates\n\n    ```java\n    int maxRecords = 100;\n    int batchSize = 4;\n    String dmlStr = \"INSERT INTO test VALUES ( :a, :b, :c, :d, :e )\";\n    Map\u003cString, Object\u003e parameters = toMap(\"a\", 1, \"b\", \"Test String\", \"c\", new Date(), \"d\", new Date(), \"e\", \"0.12345\");\n\n    MPreparedStatement st = new MPreparedStatement(conn, dmlStr, batchSize);\n\n    for (int i=0; i \u003c maxRecords; i++) {\n        parameters.put(\"a\", i);\n        parameters.put(\"b\", \"Test String \" + i);\n\n        // submit a new set of parameter values and execute automatically after 4 records\n        int[] results = st.addAndExecuteBatch(parameters);\n    }\n    // submit any outstanding records\n    st.executeBatch();\n\n    ```\n\n3) We can query our table\n\n    ```java\n    String qryStr = \"SELECT Count(*) FROM test WHERE a = :a or b = :b\";\n    Map\u003cString, Object\u003e parameters = toMap(\"a\", 1, \"b\", \"Test String\", \"c\", new Date(), \"d\", new Date(), \"e\", \"0.12345\");\n    MPreparedStatement st = new MPreparedStatement(conn, qryStr);\n     ResultSet rs = st.executeQuery(parameters);\n    ```\n\n4) We can rewrite our statement and inject the parameter values directly (useful for Oracle DDLs)\n\n    ```java\n    Date dateParameterValue = new Date();\n\n    HashMap\u003cString, Object\u003e parameters = new HashMap\u003c\u003e();\n    parameters.put(\"param1\", \"Test String\");\n    parameters.put(\"param2\", 2);\n    parameters.put(\"param3\", dateParameterValue);\n\n    String sqlStr = \"select :param1, :param2, :param3;\";\n    String rewrittenSqlStr = MJdbcTools.rewriteStatementWithNamedParameters(sqlStr, parameters);\n\n    Assertions.assertEquals(\"SELECT 'Test String', 2, \" + getSQLDateTimeStr(dateParameterValue), rewrittenSqlStr);\n\n    sqlStr = \"UPDATE tableName SET a = :param1, b = :param2, c = :param3;\";\n    rewrittenSqlStr = MJdbcTools.rewriteStatementWithNamedParameters(sqlStr, parameters);\n\n    Assertions.assertEquals(\"UPDATE tableName SET a = 'Test String', b = 2, c = \" + getSQLDateTimeStr(dateParameterValue), rewrittenSqlStr);\n    ```\n\n5) We can retrieve the information about the used parameters for building a UI Dialog\n\n    ```java\n    String qryStr = \"SELECT * FROM test WHERE d = :d and c = :c and b = :b and a = :a and e = :e\";\n    MPreparedStatement st = new MPreparedStatement(conn, qryStr);\n\n    List\u003cMNamedParameter\u003e parameters = st.getNamedParametersByAppearance();\n    ```\n\n    Output of the List:\n\n    ```text\n    INFO: Found Named Parameters:\n    D\tjava.sql.Timestamp\n    C\tjava.sql.Date\n    B\tjava.lang.String\n    A\tjava.math.BigDecimal\n    E\tjava.math.BigDecimal\n    ```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmanticore-projects%2Fmjdbcutils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmanticore-projects%2Fmjdbcutils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmanticore-projects%2Fmjdbcutils/lists"}