0

I want to save data in byte code format to my MySql db and retrieve it.

Example

String s = "String To Byte Array";

I am converting it to byte code using base64 library, so it becomes -

"U3RyaW5nIFRvIEJ5dGUgQXJyYXk="

Now I am saving this value in my MySql database in column with data type longtext

After fetching this value from DB I want to convert it in to original format.

2 Answers 2

1

You can decode the base64 back to string. This might help you.

https://examples.javacodegeeks.com/core-java/apache/commons/codec/decode-base64/

Sign up to request clarification or add additional context in comments.

Comments

1

Once you obtained the encoded string from the database, you can obtain an instance of class Decoder and decode the string in this way:

Decoder decoder = Base64.getDecoder();
byte[] bytes = decoder.decode(encoded.getBytes());
String decoded = new String(bytes);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.