Access MySQL on an Android App (Android Studio)

Thanks to Taseen Amin for this tutorial. I post this rashly. I’ll explain this tutorial when I get time, soon.

file app/src/main/res/layout/ activity_main.xml

<RelativeLayout xmlns:android=""
xmlns:tools="" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">

android:id="@+id/result" />


file app/src/main/java/

package com.ditaoktaria.classic;

import android.os.StrictMode;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONObject;
import java.lang.String;

import static;
public class MainActivity extends ActionBarActivity {

TextView resultView;
protected void onCreate(Bundle savedInstanceState) {
resultView = (TextView) findViewById(;

public void getData(){
String result ="";
InputStream isr = null;
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("");
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
isr = entity.getContent();
catch (Exception e){
Log.e("log_tag","Error in http connection"+e.toString());
resultView.setText("Couldnt connect to database");

//convert response to String

BufferedReader reader = new BufferedReader(new InputStreamReader(isr,"iso-8859-1"),8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line=reader.readLine()) != null) {
sb.append(line + "\n");
catch(Exception e){
Log.e("log_tag","Error converting result"+e.toString());

try {
String s = "";
JSONArray jArray = new JSONArray(result);

for(int i=0; i<jArray.length(); i++){
JSONObject json = jArray.getJSONObject(i);
s = s+
"idLecturer : "+json.getInt("idLecturer")+"\n"+
"username : "+json.getString("username")+"\n"+
"pass : "+json.getString("pass")+"\n"+
"fullName :"+json.getString("fullName")+"\n\n";



catch (Exception e){
//to do handle exception
Log.e("Log_tag","Error Parsing Data"+e.toString());


public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(, menu);
return true;

public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();

//noinspection SimplifiableIfStatement
if (id == {
return true;

return super.onOptionsItemSelected(item);

file app/src/main/AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=""
package="com.ditaoktaria.classic" >

android:theme="@style/AppTheme" >
android:label="@string/app_name" >
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
<uses-permission android:name="android.permission.INTERNET"></uses-permission>


access mysql on android

access mysql on android

Start XAMPP on Yosemite OSX 10.10 (error example)

1. How to start your XAMPP services?

XAMPP control panel on OSX named manager-osx

xampp control panel

xampp control panel


2. Go to tab “manage server” then start the apache and mysql service.

3. If you can’t start the mysql servie, open your terminal and execute this command :

sudo /Applications/XAMPP/xamppfiles/bin/mysql.server start

4. You might see ” starting mysql….. success” but Mysql database on manager-osx is still not running.

Don’t worry, it just takes a while for it to become “running”, you can just open http://localhost/phpmyadmin on your browser and you will see that it actually has been started already.

Good luck !

Taqobalallahu minna wa minkum, taqobbal yaa karim. Mohon maaf lahir dan batin ya teman2 semuanya. Please forgive all of my words and attitude that may hurt you. Maafkan kekhilafan saya. Happy eid mubarak ! Allahu akbar allahu akbar, allahu akbar :) – with Dhinda Maydhita

View on Path

Health chicken grill



  • 1 tablespoon olive oil
  • 1/2 finely chopped red onion
  • 1/2 green bell pepper, finely chopped
  • 1 1/2 cups barbecue sauce
  • 4 (5-ounce) skinless, boneless chicken breast halves
  • 1/4 teaspoon salt
  • 1/4 teaspoon freshly ground black pepper


1. Preheat grill.

2. Warm the oil in a medium saucepan over medium-low heat. Add the onion and green pepper; cook 5 minutes, stirring, until softened. Stir in barbecue sauce. Cook for 3 minutes to warm through and blend flavors, stirring often.

3. Season chicken with salt and pepper. Combine the chicken and 1 cup of the sauce in a large zip-top plastic bag; flip to coat. Marinate in the refrigerator for 10 minutes or up to 2 hours.

4. Remove the chicken from the marinade; discard remaining marinade and bag. Place the chicken on an oiled grill over medium-hot coals; cook 12 minutes, turning once. Serve chicken with the remaining barbecue sauce.