Named placeholders for SQL #1467
Unanswered
johnfoldager
asked this question in
Q&A
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. |
3 replies
|
Greetings. A first commit: https://github.com/manticore-projects/MJdbcUtils I will add more stuff over the next couple of days. |
12 replies
|
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); |
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
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 (
:idand: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.All reactions