Druid
源码
git clone https://github.com/alibaba/druid.git
cd druid && mvn install
// 如果报错..
mvn install -Dmaven.javadoc.skip=true -Dmaven.test.skip=true
Maven
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.12</version>
</dependency>
使用SQL Parser示例
String sql = "INSERT INTO `table_name` VALUES(...);";
MySqlStatementParser parser = new MySqlStatementParser(sql);
SQLInsertStatement sqlStatement = parser.parseInsert();
List<SQLExpr> values = sqlStatement.getValues().getValues();
String oldValue = values.get(4).toString().replace("'", "");
...
// 重新赋值
values.set(4, new SQLNCharExpr(newValue));
String finalSql = "INSERT INTO `table_name`" + sqlStatement.getValues().toString() + ";";
...