srt_cloud/srt-data-development/src/test/java/com/text/dome/a.java

33 lines
1.2 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package com.text.dome;
import com.alibaba.druid.sql.ast.SQLObject;
import com.alibaba.druid.sql.ast.SQLStatement;
import com.alibaba.druid.sql.parser.SQLParserUtils;
import com.alibaba.druid.sql.parser.SQLStatementParser;
import jdk.nashorn.internal.runtime.ParserException;
import java.util.List;
import static com.alibaba.druid.sql.SQLUtils.toSQLString;
public class a {
public static void main(String[] args) {
String str = "create table `tb_user` (\n" +
" `id` varchar(22) not null COMMENT '主键id',\n" +
" `usercode` varchar(11) DEFAULT null COMMENT '手机号',\n" +
" `name` varchar(10) DEFAULT nu";
System.out.println("格式化之前:");
System.out.println(str);
System.out.println("格式化之后:");
try {
SQLStatementParser parser = SQLParserUtils.createSQLStatementParser(str, "mysql");
List<SQLStatement> statementList = parser.parseStatementList();
str = toSQLString((SQLObject) statementList, "mysql");
System.out.println(str);
} catch (ParserException e) {
System.out.println("SQL转换中发生了错误"+e.getMessage());
}
}
}