0

I have created several classes in android client application corresponding to each database table (just like concept of Entity-Objects).

i want to retrieve data from database of the server to android client application and then assign that returned data set to objects of those created classes to further process the data and apply some logic.

I also want send data from android to server in the form of objects to process them on server or insert/update in the database.

(I can send the data to Servlet using HttpClient and HttpPost but don't know how to send objects and how to receive result set of database in the form of objects).

I'm new to client-server programming so my this approach might be wrong, if so then please correct me. any sample code will be appreciated.

W.S
  • 931
  • 1
  • 10
  • 36

1 Answers1

2

normally you would send some kind of String to the server which represents your Object. You could do that by generating JSON. There are nice libraries like GSON which can help you with that

Tim
  • 6,692
  • 2
  • 25
  • 30
  • 2
    +1 but I would prefer to use Native library and classes, instead of depending on Third-party API/library. – Paresh Mayani Mar 23 '12 at 11:30
  • 1
    That would be of course be a nice approach. Android already allows you to use org.json.JSONObject for such uses. – Tim Mar 23 '12 at 11:33
  • Thanks Tim! I've Tried alot but I could not do it successfully as i already mentioned i'm new to this. Can you please show me the in couple of lines to do that thing. – W.S Mar 23 '12 at 12:00
  • 1
    Imagine you have an Object called "Person" with a String name and an int age. What you're going to do is creating a new JSONObject jsonPerson and afterwards use jsonPerson.put("name",name) and jsonPerson.put("age",age). When sending to the server make sure to use jsonPerson.toString(). – Tim Mar 23 '12 at 12:12
  • @TimMesserschmidt exactly!! Agree with Tim – Paresh Mayani Mar 26 '12 at 04:42
  • what if the result set returned by database is too long, and we want to send each row as an object of class "Person" to the android client so that all "methods" and "attributes" can be accessed on android client in same way as on server (or vice versa) – W.S Apr 03 '12 at 14:29