Read a text and formatt it

I want to read a text from a text area and store it in a DB. My problem is : how can I do to format my text before store it in db.
For example if I tape this text in my text area:

"The sun was shining on the sea,
Shining with all his might:
He did his very best to make
The billows smooth and bright-
And this was odd because it was
The middle of the night."

how read the carriage return and marked them with a special character?
And when I get my text from db to a txt file, how formatting it and have a text like over.  

Thnks!
LepreRossaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

StillUnAwareCommented:
What kind of statement are You using? Is it Statement or PreparedStatement?
0
hoomanvCommented:
there are several other special characters rather than just carriage return. how do you want to escape them ?
simply use PreparedStatements, then escaping would be done automatically
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
StillUnAwareCommented:
You should use PreparedStatement for efectiveness and greater possibilities:

//I assume here You have a table 'table', having one field of type varchar(100).
//Then the prepared statement is created, where the char '?' is a placeholder for a fields value in subsequent operations
PreparedStatement ps = connection.prepareStatement("INSERT INTO table VALUES(?)");
//now insert the value
ps.setString(1, textArea.getText());

For more information on how to use PreparedStatemet's see here:
http://java.sun.com/docs/books/tutorial/jdbc/basics/prepared.html
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

objectsCommented:
why do you need to m,ark special characters, would appear you should be just saving the text as is.
0
colr__Commented:
String var = "this is the text you want to mark";
var = var.replaceAll("\n", "$$$"); // where $$$ is the special char
// then write to the DB

On reverse, just do it in reverse:

var = var.replaceAll("$$$", "\n");

colr__
0
mrigankCommented:
http://www.experts-exchange.com/Databases/Oracle/Q_21277128.html

Use chr(13)||chr(10) for a \n.

Then on select query, you do not need to do anything.
0
LepreRossaAuthor Commented:
Sorry,
but I have explained badly my problem.
I would replace carriage returns with a personal tag like :"\nt" when I read my text from a jsp and then I would to replace my special tag "\nt" with carriage return when diplay my text on jsp.
I have found this function that works on client side, I need something like this but on sever side:

function escapeVal(textarea,replaceWith){
textarea is reference to that object, replaceWith is string that will replace the encoded return
textarea.value = escape(textarea.value) encode textarea string's carriage returns

for(i=0; i<textarea.value.length; i++){
loop through string, replacing carriage return encoding with HTML break tag

if(textarea.value.indexOf("%0D%0A") > -1){
Windows encodes returns as \r\n hex
textarea.value=textarea.value.replace("%0D%0A",replaceWith)
}
else if(textarea.value.indexOf("%0A") > -1){
Unix encodes returns as \n hex
textarea.value=textarea.value.replace("%0A",replaceWith)
}
else if(textarea.value.indexOf("%0D") > -1){
Macintosh encodes returns as \r hex
textarea.value=textarea.value.replace("%0D",replaceWith)
}

}

textarea.value=unescape(textarea.value) unescape all other encoded characters
}
0
colr__Commented:
This problem appears to have been resolved.

colr__
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.