I am trying to fetch data from mysql database and populate it on a listview.
I am getting the ip address of my system like this
String link_url = "192.168.19.6";
Now in my wamp server I have a file called
/product_api/getDataProduct.php";
I now I want this file to called in eclipse I am doing this
link_url = Referensi.link+"/product_api/getDataProduct.php";
Please is this the right way of connecting android to mysql and how I do know if the file I am calling on eclipse is connected to mysql database.
this is the getDataOriduct.php file
<?php
include("koneksi.php");
$q = mysql_query('select * from produk');
$v = '{"info" : [';
while($r=mysql_fetch_array($q))
{
$ob = array("<br>","<b>","</b>");
if(strlen($v)<12)
{
$v .= '{"id_produk" : "'.$r['id_produk'].'", "nama_produk" : "'.$r['nama_produk'].'", "harga" : "'.$r['harga'].'", "deskripsi" : "'.$r['deskripsi'].'", "stok" : "'.$r['stok'].'", "gambar" : "'.str_replace($ob,"",$r['gambar']).'"}';
}
else
{
$v .= ',{"id_produk" : "'.$r['id_produk'].'", "nama_produk" : "'.$r['nama_produk'].'", "harga" : "'.$r['harga'].'", "deskripsi" : "'.$r['deskripsi'].'", "stok" : "'.$r['stok'].'", "gambar" : "'.str_replace($ob,"",$r['gambar']).'"}';
}
}
$v .= ']}';
echo $v;
?>
this is the included file
<?php
$conn = mysql_connect("localhost","root","");
$db = mysql_select_db("android_tokobaju");
?>
this is where the error took place and this method is defined in oncreate method
JSONParser jParser = new JSONParser();
String nlink_url = link_url +"/product_api/getDataProduct.php";
JSONObject json = jParser.AmbilJson(nlink_url);
This is the stacktrace
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ecommysql.yonandroid/com.ecommysql.yonandroid.PhotoProduk}: java.lang.IllegalStateException: Target host must not be null, or set in parameters.
This is the AmbilJson function
public JSONObject AmbilJson(String url) {
// Making HTTP request
try {
// defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
}
Please with the above is my database connected to mysql db. Thanks