Question

I'm trying to find a explanation why Oracle driver, by default, escapes end-line character "\n" to a escaped string "\\n", that makes the "\n" to show up when I print it. I'd also like to get some suggestions on how to deal with it in a elegante way besides simply replacing "\\n" to "\n" before printing it.

extra info:
- Oracle driver: ojdbc6.jar
- Java 1.6.0_18 and 1.7.0_45

Example:
- DB "column1" data = line1\nline2\nline3

java.sql.PreparedStatement stmt = conn.prepareStatement("SELECT column1 FROM TABLE1");  
java.sql.ResultSet rs = stmt.executeQuery();  
while (rs.next()) {  
   rs.getString(1); // it returns line1\\nline2\\nline3 
}

Appreciate any help,
Cheers

Was it helpful?

Solution

If the output from SQL*Plus shows \n and not actually starts a new line, then you have stored the two characters "\n" in your database and not an actual newline.

See http://www.unix.com/unix-advanced-expert-users/56212-sqlplus-output-new-line-character.html where the asker wants to get rid of actual line feeds in his database.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top