Java不处理“\\\<br/>”作为从“数据库”列检索的新行 [英] Java is not treating "\n" as new line when retrieved from Database column
问题描述
我正在做的是将数据库(oracle 11g)中的一些值存储为 varchar2 ,并在java中获取值获取的数据。
现在我将 \\\
作为数据库中的值,并使用
rs.getString()
。我正在获得正确的价值 \\\
。 String换行符= rs.getString( COLUMN_VALUE);
现在我解析一个HTML页面,并将整个页面作为一个字符串。配置页面有3行时间:08 AM - 11 AM
持续时间:36分钟
($)
$
现在,我将通过持续时间:到一个方法,这将返回我36分钟。
我使用什么逻辑是我得到的索引持续时间:并阅读,直到遇到\\\
。如果我将换行声明为
String newLine =\\\
;
但是如果我从数据库中获取它不起作用。
我知道我不需要将它存储在数据库中,但我不想硬编码这些项目。所以我必须将其存储在DB中。任何人都可以帮助我吗?
如果您打印 newLine
您在输出中得到 \\\
,您可能需要取消从数据库中获取的字符串。 Apache Commons Lang有一个方法:
所以你只需要调用
String newLine = StringEscapeUtils.unescapeJava(rs.getString(column_value) );
希望这有助于
I am facing a weird problem.
What I am doing is I am storing some values in DB(oracle 11g) as varchar2 and fetching the values in java and working with the fetched data.
Now I have \n as a value in DB and getting it in java using rs.getString()
. I am getting proper value \n
.
String newLine=rs.getString("column_value");
Now i parse a HTML page and get the whole page as a string.Suppose the page has 3 lines each depiciting ssome informations like below:
Time: 08 AM - 11 AM
Duration : 36 minutes
Now in code i will pass "Duration :" to a method and that will return me "36 minutes".
What logic i use is i get the index of "Duration :" and read till "\n" is encountered.Code works fine if i declare the newline as
String newLine= "\n";
But if i get it from DB it does not work. I know i don't need to store this in DB but i don't want to hardcode these items. So i have to store it in DB only. Can anyone help me out in this???
If when you print the newLine
you get \n
in the output, you might have to unescape the string you get from the DB. The Apache Commons Lang have a method for that:
So you would have simply to call
String newLine = StringEscapeUtils.unescapeJava(rs.getString("column_value"));
Hope this helps
这篇关于Java不处理“\\\<br/>”作为从“数据库”列检索的新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!