有什么办法可以使用Eclipse编写(复制粘贴)使用Java字符串文字格式的SQL查询格式吗? [英] Is there any way I can write (copy-paste) nicely-formatted SQL queries in Java string literals using Eclipse?

查看:357
本文介绍了有什么办法可以使用Eclipse编写(复制粘贴)使用Java字符串文字格式的SQL查询格式吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我希望在Java中使用SQL查询时,我通常将它们保存在最终的String变量中。现在,当字符串太大时,它会超出页面宽度,我们不得不手动中断它(在eclipse中,转到字符串中的特定位置,然后输入,并为每个生成的较小的部分),或者我们可以在Eclipse中设置格式化程序,仅允许(例如)每行100个字符。但是字符串没有以合乎逻辑的方式破坏。

When I wish to use SQL queries in Java, I usually hold them in final String variables. Now, when the string is too large, it goes out of page breadth, and we either have to manually break it (In eclipse, go to a particular place in the string, and place enter, and do it for each of the resulting smaller part), or we can set the formatter in Eclipse to allow only (say) 100 characters per line. But the string is not broken in a logical manner.

我可以在SQL Developer(比如说)中很好地格式化一个查询,但是如果我在Java中粘贴,我将不得不手动设置所有的最终引号,而code> + 符号使其成为一个合适的Java字符串。我只想知道一种将格式正确的SQL查询复制粘贴到Java文件中的方法。我正在使用Eclipse。

I can format a query nicely in SQL Developer (say), but if I paste that in Java, I will have to manually set all the end quotes, and + symbols to make it a proper Java string. I just want to know a way to have a properly formatted SQL query copy-pasted directly into a Java file. I am using Eclipse.

也许当一个查询格式如下:

Perhaps when a query is formatted like :

SELECT
  *
 FROM
  something
 WHERE
  id=4;

然后当它粘贴在一个java字符串中时,我们可以像下面这样:

then when its pasted inside a java string, we can have it like :

"SELECT" +
  " *" +
 " FROM" +
  " something" + 
 " WHERE";
  id=4;


推荐答案

在Eclipse中,在Window> Preferences> Java> Editor >打字检查粘贴到字符串文字时的转义文本复选框。

In Eclipse, in Window > Preferences under Java > Editor > Typing check the "Escape text when pasting into a string literal" checkbox.

它将格式化纯文本:

line1
line2
line3

to:

private final String TEXT = "line1\r\n" + 
            "line2\r\n" + 
            "line3";

这是Eclipse Helios的输出。
类似的问题:环绕引号

This is the output on Eclipse Helios. A similar question: Surround with quotation marks

这篇关于有什么办法可以使用Eclipse编写(复制粘贴)使用Java字符串文字格式的SQL查询格式吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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