Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to convert sql data to json object in servlet  RSS feed

 
mustafa demir
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, firstly i'm sorry about my bad language,  I made a servlet that reads data from db now i want to convert this sql data to json but when i try to create json object i'm getting this error 'JsonObject is abstract; cannot be instantiated' now how can i convert data coming from database to json file and how can i read it help me out !  here my servlet
 
Stephan van Hulst
Saloon Keeper
Posts: 7683
139
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Mustafa, welcome to CodeRanch!

I suggest you use JAX-B with a JSON processor such as Jackson. If you combine this with an MVC framework such as Spring or Jersey, you can just return plain objects that will automatically get serialized to JSON for you.

Please don't output HTML directly from your servlet or controllers. Use a templating language like JSP or Thymeleaf to return HTML pages from your web application.
 
mustafa demir
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did it thank you so much i add json jar file then i've created a json object and it's done and i'm gonna use angularjs for output  thanks again
 
Stephan van Hulst
Saloon Keeper
Posts: 7683
139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Happy you sorted it out :)
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!