Java 有没有可以将 SQL 语句提取到文件中的 IDE/工具?
大家好,Java 世界中有没有可用的工具可以解析/读取源文件并将 SQL 语句提取到文本文件中。这是一项复杂的任务,因为您可以在源代码中以不同的方式编写 SQL 语句(例如:使用 +
符号或使用 .append()
),甚至可以条件构建SQL。
Hi is there any tool available in Java world that will parse/read a source file and pull SQL statements out in to a text file. This is a complex task given that you can write SQL statements in different fashion within the source (ex: using +
sign or using .append()
) or even conditional building of SQL.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我们一直在考虑这样做。这需要:
1)一个完整的Java解析器
2)完全的控制和数据流分析,这样你就可以
跟踪值如何通过代码传播
3) 识别 SQL (JDBC) 调用,跟踪数据流
SQL查询回到其起源,并象征性地解释
沿数据流路径的一组操作以确定
明显的 SQL 操作。
DMS 软件再工程工具包 是用于解析语言的通用引擎。 DMS 具有完整的 Java 前端(满足条件 1),用于计算本地控制和全局数据数据流分析(条件 2)。 DMS 可配置为提取代码属性,因此我们可以将其配置为执行第 3 步。仍然不是一项简单的任务。
但遗憾的是,所请求的工具尚不可用。
We've been considering doing this. This requires:
1) A full Java parser
2) Full control and data flow analysis, so that you can
track how values propagate through the code
3) Recognition of SQL (JDBC) calls, tracking data flows for the
SQL query back to their origins, and symbolically intrepreting the
set of operations along the data flow paths to determine
the apparant SQL operation.
The DMS Software Reengineering Toolkit is a generic engine for parsing langauges. DMS has a full Java front end (meets condition 1) that computes local control and global data data flow analysis (condition 2). DMS is configurable to extract code properties, so it could be configured we think to do 3. Still not a trivial task.
But alas, the requested tool is not available yet.
我从来没有遇到过。有几次人们不得不做这样的事情,他们最终会编写一个程序来完成它,因为这并不是真正可以概括的事情。
Not that I've ever come across. The few times that people have had to do something like this, they have ended up writing a program to do it, because it's not really something you can generalise.
您是否考虑过将准备好的语句的 SQL 放在属性文件(或语言资源包)中并从那里读取它们?
Have you considered having the SQL for the prepared statements in a property file (or language resource bundle) and read them from there?
检查 www.antlr.org,他们有 PL/SQL、MySQL 和 Java 1.6 的语法。如果您只对 SQL 感兴趣,那么 SQL 语法可能是您可以构建的基础。
可能有更简单的方法,比如从 JDBC 驱动程序日志/线路/数据库服务器日志读取伪 SQL 将产生更一致的语法。
Check www.antlr.org, they have grammars for PL/SQL, MySQL and Java 1.6. If you only interested in SQL, probably SQL grammar could be something you can build upon.
There could be easier ways about it thought, like reading pseudo SQL from JDBC driver log/wire/from database server log will produce more consistent syntax.