Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

How to Replace String Values in JSQLParser version 5? #2148

Discussion options

Tried following the example in the wikia and I'm not able to get the censored values

How should it be done in the new version?

You must be logged in to vote

Please see here
You are overriding the wrong methods. Instead use the methods with the generics.

Replies: 2 comments

Comment options

The exact output of

class ReplaceColumnValues {
 static class ReplaceColumnAndLongValues extends ExpressionDeParser {
 @Override
 public void visit(StringValue stringValue) {
 this.getBuffer().append("?");
 }
 @Override
 public void visit(LongValue longValue) {
 this.getBuffer().append("?");
 }
 }
 public static String cleanStatement(String sql) throws JSQLParserException {
 StringBuilder buffer = new StringBuilder();
 ExpressionDeParser expr = new ReplaceColumnAndLongValues();
 SelectDeParser selectDeparser = new SelectDeParser(expr, buffer);
 expr.setSelectVisitor(selectDeparser);
 expr.setBuffer(buffer);
 StatementDeParser stmtDeparser = new StatementDeParser(expr, selectDeparser, buffer);
 Statement stmt = CCJSqlParserUtil.parse(sql);
 stmt.accept(stmtDeparser);
 return stmtDeparser.getBuffer().toString();
 }
 public static void main(String[] args) throws JSQLParserException {
 System.out.println(cleanStatement("SELECT 'abc', 5 FROM mytable WHERE col='test'"));
 System.out.println(cleanStatement("UPDATE table1 A SET A.columna = 'XXX' WHERE A.cod_table = 'YYY'"));
 System.out.println(cleanStatement("INSERT INTO example (num, name, address, tel) VALUES (1, 'name', 'test ', '1234-1234')"));
 System.out.println(cleanStatement("DELETE FROM table1 where col=5 and col2=4"));
 }
}

is

SELECT 'abc', 5 FROM mytable WHERE col = 'test'
UPDATE table1 A SET A.columna = 'XXX' WHERE A.cod_table = 'YYY'
INSERT INTO example (num, name, address, tel) VALUES (1, 'name', 'test ', '1234-1234')
DELETE FROM table1 WHERE col = 5 AND col2 = 4

in com.github.jsqlparser:jsqlparser:5.1

You must be logged in to vote
0 replies
Comment options

Please see here
You are overriding the wrong methods. Instead use the methods with the generics.

You must be logged in to vote
0 replies
Answer selected by JevonCowell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /