You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importcom.alibaba.druid.sql.visitor.ParameterizedOutputVisitorUtils;
finalStringdbType = JdbcConstants.MYSQL;
Stringsql = "select * from t where id = 1 or id = 2 or id = 3";
Stringpsql = ParameterizedOutputVisitorUtils.parameterize(sql, dbType);
assertEquals("SELECT *\n" +
"FROM t\n" +
"WHERE id = ?", psql);
3. 获取具体参数化后的常量值
finalStringdbType = JdbcConstants.MYSQL;
// 参数化SQL是输出的参数保存在这个List中List<Object> outParameters = newArrayList<Object>();
Stringsql = "select * from t where id = 101 and age = 102 or name = 'wenshao'";
Stringpsql = ParameterizedOutputVisitorUtils.parameterize(sql, dbType, outParameters);
assertEquals("SELECT *\n" +
"FROM t\n" +
"WHERE id = ?\n" +
"\tAND age = ?\n" +
"\tOR name = ?", psql);
assertEquals(3, outParameters.size());
assertEquals(101, outParameters.get(0));
assertEquals(102, outParameters.get(1));
assertEquals("wenshao", outParameters.get(2));