Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Saving and retrieving formatted data from database

 
Vinay Singh
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
 
Vassili Vladimir
Ranch Hand
Posts: 1585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ...
 
Vinay Singh
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Adam Schaible
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic