wood burning stoves 2.0*
The moose likes Java in General and the fly likes how to convert object into string or text like ascii etc without losing object persistence Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "how to convert object into string or text like ascii etc without losing object persistence" Watch "how to convert object into string or text like ascii etc without losing object persistence" New topic
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: 2258
    
    3

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: 19655
    
  18

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 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to convert object into string or text like ascii etc without losing object persistence
 
Similar Threads
How to store SecretKey in database?
Migration from HSQLDB to ORACLE
convert String into Object
mysql enum to java string
mysql enum to java string