0

We are storing uploaded text files in a SQL server data. The field type is image.

The file upload and download correctly, what I want to do now is load the actual text content into a String variable directly from the database record.

Can anyone advise on how to do this please?

1 Answer 1

3

Depends on how you read the data from the db. If you get a byte array, you could use new String(bytes);

Btw, why don't you use the CLOB datatype (or the equivalent for your server) for the field? This should normally cause the Java driver to return the String directly.

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

3 Comments

Thanks Thomas; the String(bytes) answer was just the prompt I needed. Problem solved. Cheers.
Note that using new String(byte[]) without a second parameter will use the platform default encoding which can lead to problems when you run it on different computers or with different configurations! Whenever possible, you should specify which encoding the text is in!
@Joachim That's true, and id the endocing can vary, it might be stored in the dataset as well.

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.