开发者

Connect Android with database

I am doing an academical project on Electronic Voting a开发者_StackOverflow社区nd I need to connect Android application with my MySQL database designed in xammp. Also, I am using the eclipse program in order to do my project.

Could you help me to find the way to connect android with xammp?


If you need the application to connect to the database on a webserver then it might be best to create a REST service on the webserver and then access it via that.


A sample code here

private static String loginURL = "http://xxxx/databasename/index.php";//databasename as in xampp
//note:xxxx=10.0.2.2 for emulator,
//xxxx=ip address from ipconfig cmd if android device on same network as pc.

public JSONObject loginUser(String email, String password){
    // Building Parameters
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("TAG", "SampleLogin"));
    params.add(new BasicNameValuePair("email", email));
    params.add(new BasicNameValuePair("password", password));
    JSONObject json = jsonParser.makeHttpRequest(loginURL,"POST", params);
    return json;
}

To share internet from PC itself,use windows virtual wifi router and share your pc internet to android device. For android device to access tables,Ensure you've given access rights{edit httpd-xampp.conf to "Allow from all" instead of " Require local" inside tag}

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜