i am going to develop cloud based application in java
, i have Linux web server with mysql
installed
so i come up with 2 different ways to query database, both solutions are communicate trough http requests
and both methods have their own advantages and disadvantages
i am using below example for demonstrate solutions
database on the server
-- fruit--
name price
Apple 10
Banana 5
Mango 4
lets say i want to get all the fruit items from database
Solution 1 : write database access class using PHP
in Server side and let java application send query via http requst
ex:- java application will send query SELECT * FROM fruit
then server side PHP
will return query result as `JSON' format
-this is super reusable and can use for any future cloud database access and it is clean code because all the implementations are don in JAVA
side except database access
Solution 2 : Write both Fruit class and database classes in server side and let JAVA
application to call server side functions via http
requests
its like getAllFruits()
-in this way i have to implement all the DAO classes in server side and it is more coding,less re usability in another project also since DAO is implemented in PHP side maintenance effort is higher than solution 1
i think Solution 1 is the best because of re usability and simplicity, i am afraid that database query will be sent via http
request which is not feel good for me, so i really appreciate your ideas and comments since i am new to this kind of applications, if you have any other solutions or Advantages and disadvantages i am also open for those
also i was wondering about how other companies implement it