-1

Firstly , this is a java program but not Android.

I write a very simple API to get the DB data in Php like below code:

<?php
$query = "Select * from staff order by staff_name";
$reuslt = $mysqli->query($query);
echo json_encode($reuslt->fetch_object());

Suppose that i can get the JSON object in the following URL easily in Android or Php: http://localhost/Testing/simpleWebService.php

But how can i get it in Java?? I have searched it in Google but the result seems not what i actually want and useful to me (Reason is i am quite Junior to Java ,Lack of knowledge in Web Service, not accurate keywords inputted........). I found sth like Jersey, JAX-RS but i don't think this help and the way to get the JSON from the Web Service is complex like that.

Can anyone help ? Thank you very much!!!!!!

Ricky
  • 13
  • 4

1 Answers1

0

The crux of the matter is that you have to replace the behaviour implemented by PHP's json_encode function in Java ie. you have got to find a way to convert the recordset representation of your data to JSON.

1 approach would be to manually convert your recordset to a collection of POJO's then use Jackson to generate the JSON.

However, there are loads of frameworks that make this easier for you to achieve.

What Java framework are you using as that will constrain your future decisions to some degree? How are you reading from your DB - using JDBC API or using an ORM or other library?

jacks
  • 4,614
  • 24
  • 34
  • Actually , i need to import this java program to a middle ware .I afraid that i cannot use a framework because of the size. As i have said, i am new to Java and i do not have the chance to use a framework ,the programs are not that huge/maintenance work. – Ricky Jul 28 '15 at 02:54
  • Just use the Jackson libraries then. – jacks Jul 28 '15 at 09:53