在Eclipse中,如何在Java字符串中获取SQL文本? [英] In Eclipse, how can get the SQL text when it's in a Java String?

查看:280
本文介绍了在Eclipse中,如何在Java字符串中获取SQL文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Java String中有一个非常长的SQL语句。在eclipse中,如何轻松获取SQL语句的文本,而不需要使用Java String语法呢?我已经手动删除它,但在IntelliJ Idea中,可以让一个人获取文本,而无需执行任何手动格式化工作来删除Java String语法(例如 + 字符)Eclipse有类似的功能吗?



作为一个额外的好处,我会问如果还可以使用在IDE中格式化的换行符来获取字符串,即使字符串本身中没有 \\\
字符。

解决方案

根据您的SQL客户端,可以使用此功能
我知道TOAD具有内置的功能,我还记得松鼠有它。



所以当粘贴到TOAD的SQL编辑器中时,代码将自动从Java字符串语法中提取,我记得它也是使用StringBuffer / StringBuilder等构造。



请参阅: http://dev.toadformysql.com/webhelp/Content/Editor/Convert_SQL_Embedded_SQL.htm



或者你可以为您的示例代码创建一个简单的正则表达式,例如此jsfiddle
它适用于sql的正则表达式,如:

 select something \r\\\
+
from dual+
where 1 = 1\r\\\
;

jsfiddle应该输出

 从双
中选择一个
,其中1 = 1

仍然没有精美的格式(即使使用< pre> 标签,它应该保留空格),但是你的SQL IDE应该帮助你吗? / p>

I have a very long SQL statement inside of a Java String. In eclipse, how can I easily get the SQL statement's text without the Java String syntax? I've been manually removing it, but in IntelliJ Idea, it's possible for one to get the text without having to do any manual formatting work to remove the Java String syntax (such as " and + characters). Does Eclipse have a similar feature?

As an added bonus, I would ask if it were also possible to get the string with the newlines put in place as it was formatted in the IDE, even if no \n characters were present in the string itself.

解决方案

Depending on your SQL client, it could have this feature. I know that TOAD has this feature built-in. I also remember Squirrel having it.

So when pasted into the SQL editor of TOAD, the code is automatically extracted from the Java string syntax. I remember that it also worked with constructs like StringBuffer/StringBuilder.

See: http://dev.toadformysql.com/webhelp/Content/Editor/Convert_SQL_Embedded_SQL.htm

Or you can create a simple regexp working for your sample code, for example this jsfiddle. It works with a regex for sql like:

"select something \r\n" +
"  from dual " +
 "where 1 = 1\r\n"; 

The jsfiddle should output

select something
  from dual
 where 1=1

Still it is not beautifully formatted (even if with the <pre> tag it should preserve spaces), but your SQL IDE should help you with that, no?

这篇关于在Eclipse中,如何在Java字符串中获取SQL文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆