Reputation: 97
I am new to Struts and Android. We have developed a Struts application. Now, we are looking to develop some modules in Android where same functionalities to be developed. So, it requires a database (MySQL) interaction.
It would be grateful for any ideas. Will it require PHP or Webservices?
Upvotes: 3
Views: 10199
Reputation: 6166
It will require web-services,
You can not access your MySqlSQL/Oracle database from Your application. just because of all of these database are deployed some other environment , and can not deploy huge database like MySQL on a mobile environment.
So that you need to use web-services for accessing those database(MySQL/Oracle).
WebServices
: Just kind of a mechanism which call some server side script like PHP, ASP, JSP
etc.
All these script have API for accessing your MySQL database. finally this script will return result in form JSON/XML
to your application. through HTTP connection.
YourAPP
->It Will execute some peace code which talk to your server (Calling web services-> getStudent()-)
Server
-> *It will execute something like getStudent()- "select * from student" - > Budle data into json/xml formet. - > return as response to your App.*
YourApp
-> callback(Student data) -> it will get response.
Upvotes: 3
Reputation: 93569
Do not directly connect an Android device to a production database. This is insecure for two reasons.
It means you can't firewall off your database, and must leave it on the open internet. This increases the ability of hackers to attack it directly.
To connect to the database, you need login info. That means you have to put it in the app. This makes it trivial for an attacker to decompile and get it. At that point you've handed them your database. The correct way to fix this is to put a webservice between them, and have the Android app only directly connect to the webservice. Then only the webservice, which is safe on your own servers, needs to know the password.
Upvotes: 1
Reputation: 169
If your database is small you can use sqllite on the phone and store the database on the phone.
If you want to keep it online follow:
In your android project you have to make an async Task to send an http request to a web script which takes care of the statement.
Its the same as sending an html form, you send the data by get or post and you recieve them in php the same way,connect to sql, query your database, return your results, then you return them to the phone in json or xml format.
In the phone you take the results which are the xml or json format data and parse them and do with them whatever you want.
You can also update/alter/insert/delete/... the database this way aswell.
The SQLite basic tutorial:(This is a basic tutorial which i think might help you) http://www.vogella.com/tutorials/AndroidSQLite/article.html#todo_database
The online sql database tutorial : http://androidprogramz.blogspot.com/2012/07/connect-mysql-database-from-android.html (this is also a basic tutorial that shows you how to update insert select and almost everything.)
Good Luck :)
Upvotes: 0
Reputation: 2200
You should use webservices to use datas from db.
To do this, you may learn what json and rest are. You can use them on sv side. And there is Gson to learn on android client side. It helps you to parse your json datas.
There are lots of tutorials about it on google.
accessing-web-service-from-android.html
Upvotes: 0