确认
- [x] 我的版本是最新版本, 我的版本号与 version 相同, 并且项目里无依赖冲突
- [x] 我已经在 issue 中搜索过, 确认问题没有被提出过
- [x] 我已经修改标题, 将标题中的 描述 替换为你的想法(不得删除 描述 前面的部分)
功能改进
public class SqlParseTest {
public static void main(String[] args) {
String sql = "select * from [db1].dbo.table1";
try {
Statement parse = JsqlParserGlobal.parse(sql);
} catch (JSQLParserException e) {
throw new RuntimeException(e);
}
}
}
报错内容:Caused by: net.sf.jsqlparser.JSQLParserException: net.sf.jsqlparser.parser.ParseException: Encountered unexpected token: "from" "FROM"
是否考虑:
String sqlStr="select 1 from [sample_table] where [a]=[b]";
// T-SQL Square Bracket Quotation
Statement stmt = CCJSqlParserUtil.parse(
sqlStr
, parser -> parser
.withSquareBracketQuotation(true)
);
参考资料
https://github.com/JSQLParser/JSqlParser/issues/1703
Comment From: jhd147350
其他解决办法:将方括号替换为双引号,sqlserver也支持双引号。 select * from [db1].dbo.table1 -> select * from "db1".dbo.table1
库名带了特殊符号,必须用方括号或双引号括起来,请有同样问题的人进了避免特殊符号的使用。
Comment From: miemieYaho
see 'JsqlParserGlobal'