1.SQLServer
根据以下正则匹配与if校验逻辑,可提取SQLServer的脚本文件里CREATE TABLE的字段类型,比如:varchar、datetime等。
public class SqlFileParser {
public static void main(String[] args) {
String sqlFilePath = "K:\\test.sql";
try {
List<String> fieldLines = extractFieldTypesFromCreateTable(sqlFilePath);
for (String fieldLine : fieldLines) {
String regex = "\\s*\"[\\w\\\"]+\"\\s+(\\w+.*?)";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(fieldLine);
if (matcher.find()) {
String fieldType = matcher.group(1);
System.out.println(fieldType);
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
private static List<String> extractFieldTypesF