File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Saving and retrieving formatted data from database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Saving and retrieving formatted data from database" Watch "Saving and retrieving formatted data from database" New topic
Author

Saving and retrieving formatted data from database

Vinay Singh
Ranch Hand

Joined: Dec 15, 2004
Posts: 174
We want to save the data in following format

class Bus extends Vehicle {}
class TestSamp {
public static void main(String [] args) {

ArrayList<Car> a = new ArrayList<Car>();
}

I am saving this data as text. When I retrieve the data I get it as

class Bus extends Vehicle {}class TestSamp {public static void main(String [] args) {ArrayList<Car> a = new ArrayList<Car>();}


Is there any way I can save this data as it is ?


Technical quiz and interview questions   SCJP 6 mock practice test
Vassili Vladimir
Ranch Hand

Joined: Mar 08, 2007
Posts: 1585
Hi,

You want to save the data as text or object hierarchies ?

I did not get your idea ...

If you are trying to save object hierarchies, the go for an ORM framework like Hibernate or Toplink ...

Best of luck ...


Vassili ...
SCJP 5.0, SCWCD 1.4, SCJA 1.0
Vinay Singh
Ranch Hand

Joined: Dec 15, 2004
Posts: 174
We want to save data as text without altering the formatting.
This data has been entered into text area from a browser by the user.
When saving this database strips the white spaces and new line characters.
We want to preserve the formatting.
For eg the way you type in this text box in this website, the data would be displayed exactly in same format. This is how we want it.
[ November 05, 2007: Message edited by: Vinay Singh ]
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Neither your database nor Java will be removing characters from your text.

Your class doesn't indicate any format. Can you explain a bit more about what you are doing?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Adam Schaible
Ranch Hand

Joined: Oct 04, 2007
Posts: 101
I understand... I think

You want to save string data to a database - and then retrieve it with the formatting the same. It really has nothing to do with the data in this case - that what you're trying to save is actually java code.

Design decisions aside, you could write a filter that replaces new line characthers with \n's, etc..

But you should probably do that on the way UP to the screen, not on the way down - that way your formatting isn't in your database, etc.

What's your final presnetation medium?
Vinay Singh
Ranch Hand

Joined: Dec 15, 2004
Posts: 174
Its not just java code which I need to save. It could be any text.
For eg

Today is Monday.
I am going to ask you to type this:

public class HelloBoston {
// I would have something later

}


This block I am going to save in database.
The front end is JSF with field input type as text area.

Consider java ranch forum. When I write this block , its going to be saved in database and when it would be displayed, you would see the way I have typed it.
This is what I want. I don't want bold or any other fancy stuff.
Just spaces, tabs and new lines.
I can write a parser to do this but this is a very common problem in web applications.
There should be a way to do this.




Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24168
    
  30

Originally posted by Vinay Singh:

I can write a parser to do this but this is a very common problem in web applications.
There should be a way to do this.


What people are trying to tell you is that you shouldn't have to do anything at all. Someplace in your system there must be some code which is removing newlines, tabs and spaces. Find that code, and remove it.


[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Saving and retrieving formatted data from database
 
Similar Threads
DownCast and Generics
About generics..
mock test for generics & collections
Warnings during Generic assignments
generic