Named placeholders for SQL #1467
Replies: 3 comments 16 replies
-
Greetings! Yes, this is certainly possible, however I wonder if you are not looking for a more sophisticated approach:
Rationale: this approach allows for using Prepared Statements and Batch Updates yielding in much better performance instead of parsing single statements with hard coded parameters under heavy performance penalty. In a nutshell, you would call a methods:
This is not necessary in Scope of JSQLParser, but rather belongs into a JDBC extension. |
Beta Was this translation helpful? Give feedback.
-
Greetings. A first commit: https://github.com/manticore-projects/MJdbcUtils I will add more stuff over the next couple of days. |
Beta Was this translation helpful? Give feedback.
-
I have pushed support for CREATE TABLE test (
a DECIMAL(3) PRIMARY KEY
, b VARCHAR(128) NOT NULL
, c DATE NOT NULL
, d TIMESTAMP NOT NULL
, e DECIMAL(23,5) NOT NULL
) String ddlStr = "INSERT INTO test VALUES ( :a, :b, :c, :d, :e )";
String qryStr = "SELECT Count(*) FROM test WHERE a = :a or b = :b";
Map<String, Object> parameters = toMap("a", 1, "b", "Test String", "c", new Date(), "d", new Date(), "e", "0.12345");
// Insert data
MPreparedStatement st = new MPreparedStatement(conn, ddlStr);
st.execute(parameters);
// Query data
MPreparedStatement st = new MPreparedStatement(conn, qryStr);
ResultSet rs = st.executeQuery(parameters); |
Beta Was this translation helpful? Give feedback.
-
I have a string representing a SQL statement with placeholders (
:name-of-placeholder
) like:SELECT * FROM table WHERE id = :id AND name = :name AND description LIKE "%:something%"
Is it possible to process it so that I can get each placeholder (
:id
and:name
, but not:something
) and replace each with a value (numeric or string), such that:' OR TRUE'
then ti should escape it correct in order to prevent SQL injection.Beta Was this translation helpful? Give feedback.
All reactions