| Author |
how to convert object into string or text like ascii etc without losing object persistence
|
shaharyar khan
Greenhorn
Joined: Aug 16, 2011
Posts: 9
|
|
|
hi folks, i want to know that how can we convert an object of any class into string without losing data.Actually i want to store a object into relational database where as that database only takes ascii or string format.So how can i store my object to that database so that i can get back without losing persistence of that object.thanks
|
 |
Roberto Perillo
Bartender
Joined: Dec 28, 2007
Posts: 2212
|
|
Well champ, I'd say that that wouldn't be effective. What you can do is serialize your object, and then you wouldn't store it in the database as a String, but instead, you would physically store it as a regular file. And also, instead of retrieving your object from a database, you would deserialize it from this file. I think this would do what you are looking for.
Here's a good article to get you started: Discover the secrets of the Java Serialization API.
|
Cheers, Bob "John Lennon" Perillo
SCJP, SCWCD, SCJD, SCBCD - Daileon: A Tool for Enabling Domain Annotations
|
 |
shaharyar khan
Greenhorn
Joined: Aug 16, 2011
Posts: 9
|
|
|
forget about to store in database.just tell me how can i convert it into ascii or string and then get back even from maps.
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
|
Assuming you don't want to build special support for each class, the most obvious way is to first serialize the object to a byte[] using a combination of ByteArrayOutputStream and ObjectOutputStream, then Base64 encode that byte[] into a String. Don't create a String directly from the byte[] because it will contain several "characters" that shouldn't go in Strings.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
 |
|
|
subject: how to convert object into string or text like ascii etc without losing object persistence
|
|
|