Java is not treating "\n" as new line when retrieved from Database column

try this

String newline = System.getProperty("line.separator");
boolean hasNewline = word.contains(newline);

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:

http://commons.apache.org/proper/commons-lang/javadocs/api-2.6/org/apache/commons/lang/StringEscapeUtils.html#unescapeJava(java.io.Writer, java.lang.String)

So you would have simply to call

 String newLine = StringEscapeUtils.unescapeJava(rs.getString("column_value"));

Hope this helps


The problem is that the database is adding a escape character to your string, so you end up with \\n instead of \n. To fix this you could just replace \\n with \n.

String db_string = new String("This is a string from the db \\n This should be a new line, but is not."); 
db_string = db_string.replace("\\n", "\n");

If you print this you get:
This is a string from the db
This should be a new line, but is not. //well it is now..