4. MJdbcUtils - JDBC Named Parameter Tools

Maven Badge Codacy Badge Coveralls Badge License Badge GitGub Release Badge GitGub Issues Badge

MJdbcUtils is a Java Library for the handling of Named Parameters (e. g. :parameter) in Queries or DML or DDL statements. It either replaces any Named Parameter with a Positional Parameter or rewrites the the Named Parameter with the parameter’s value and provides a convenient mapping between the Named Parameter and the provided values. Further, it provides helpers for Parameter Dialogs and Batch Updates with parameters.

Latest stable release: MJdbcUtils-1.1.0.jar

Development version: MJdbcUtils-1.2.0-SNAPSHOT.jar

GitHub Repository

Sample SQL Statement
// DML statement with Named Parameters
String dmlStr = "INSERT INTO test VALUES ( :a, :b, :c, :d, :e )";

// Helper function will fill our parameter map with values
Map<String, Object> parameters = toMap("a", 1, "b", "Test String", "c", new Date(), "d", new Date(), "e", "0.12345");

// Create a Prepared Statement, which holds our parameter mapping
MPreparedStatement st = new MPreparedStatement(conn, dmlStr);

// Execute our statement with the provided parameter values
Assertions.assertFalse( st.execute(parameters) );

Features

  • Finds Named Parameters and Positional Parameters in SQL Statements

  • Maintains a map between the Named Parameter and the derived Positional Parameters so ever Named Parameter needs to be set just one single time

  • Rewrites the statement using Positional Parameters ? or the given values (useful for DDL statements)

  • Retrieve the information about the used parameters for building a UI Dialog

  • Support for BatchUpdates and PreparedStatements with parameters