Access MySQL on an Android App (Android Studio)

Thanks to Taseen Amin http://twitter.com/taseenAdmin 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="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">

<TextView
android:text="@string/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/result" />

</RelativeLayout>

file app/src/main/java/MainActivity.java


package com.ditaoktaria.classic;

import android.os.StrictMode;
import android.support.v7.app.ActionBarActivity;
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 java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

import static com.ditaoktaria.classic.R.id.result;
public class MainActivity extends ActionBarActivity {

TextView resultView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
StrictMode.enableDefaults();
resultView = (TextView) findViewById(R.id.result);
getData();
}

public void getData(){
String result ="";
InputStream isr = null;
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://10.0.0.61/classic/getAllLectures.php");
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

try{
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");
}
isr.close();
result=sb.toString();
}
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";
}

resultView.setText(s);

}

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

}

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

@Override
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 == R.id.action_settings) {
return true;
}

return super.onOptionsItemSelected(item);
}
}

file app/src/main/AndroidManifest.xml


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

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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

</manifest>

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

http://blogs.rsc.org/fo/2014/04/09/olive-oil-may-offer-diabetes-protection/

 

Ingredients

  • 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

Preparation

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.

 

 

 

http://www.health.com/health/recipe/0,,10000001193345,00.html