0

I am working on tablet web app project, but I don't know how to create JSON file getting out info with Java connecting to database. Info is getting through of Store Procedure and data return with List<Object obj> or with ResultSet. Thanks.

3 Answers 3

1

You should use a library called json-simple

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

Comments

1

Use Jackson library to convert any Java model object into JSON.

ObjectMapper mapper = new ObjectMapper();
mapper.writeValue(new File("c:\\modelObj.json"), modelObj);

or

String s = mapper.writeValueAsString(modelObj);

Comments

1

A json file is text - so retrieve just as you would any string. If you were using a result set you could use ResultSet.getString(). Then you probably will want to deserialize it into either a domain object or some form of json object using a json parsing library.

There are lots of different libraries out there for doing this, for instance Jackson or Gson. I personally prefer gson - probably just because I'm more familiar with it and I find the API quite straight forward.

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.