简体   繁体   中英

\r\n encoding issue when reading from DB & Java

I have a Java program that stores a message like "test1\\r\\ntest2" into DB - when I print this out it gives me new line. The other thread is reading strings from DB and sending them to output with "\\r\\n" and when I try to print this out it doesn't give me newline - it just prints out "test1\\r\\ntest2" Should I change the encoding of the output?

The application is deployed on tomcat with UTF-8 encoding set.

Thanks in advance.

Are the strings actually stored in the database as "\\r\\n"?

In that case I think you have to do a

String correct = dbString.replace("\\r\\n","\r\n")
on the strings returned from the database.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM