If i read the same data from Database (Database CharacterSet is ASCIITHAI ) and appending the string to StringBuffer
StringBuffer sb = new StringBuffer(1024); sb.append("Hello, \n new line "); System.out.println(" The String is : "+sb.toString());
handat wrote:I am storing in the DB as string literal, how to store as a special character?
"\n" is a special character representing a new line. When you are storing it in a database, are you storing the value of the special character, or are you literally storing two characters, ie \ and n ?
I am facing a weired problem, When i write below code it is printing it in new line:That's because the Java compiler recognizes \n in string literals and translates them to newline characters.
If i read the same data from DatabaseYou aren't reading the same characters from the database. You are reading '\' and 'n'. No Java compiler is involved, so no translation occurs.
want to understand why it is not considering '\n' as newline when reading string from database.Because the database isn't a Java compiler.
rp0428 wrote:How each would display depends on the operating system of the end user. LF would only on a Mac (and I think not even a modern one) give the probably desired result.
Try Character value 13
That is a carriage return. Linefeed is CHR(10).
So OP could put CHR(13), CHR(10) in the DB for a CRLF or just use CHR(10) if only LF is wanted.