Ciao sto tentando di fare una app che mi legge i dati in locale da un db access , ho realizzato un script Php che mi da un autput che funziona;
<?php
/* La query SQL, */
$query="select *from tabripa" ;
/* I parametri di connessione */
$path= "D:/OneDrive/Programmazione/Android/" ;
$db_name= "dati.mdb" ;
$dsource=$path.$db_name ;
$cn_string="Provider=Microsoft.Jet.OLEDB.4.0;" ;
$cn_string.="Data Source=$dsource;" ;
$cn_string.="Jet OLEDB:Database Password=gmpa";
$response = array();
/* La connessione */
if (!file_exists($dsource) ){
die("Il database non esiste") ;
}
$cn= new COM("ADODB.Connection");
$cn->open($cn_string) ;
/* Istanziamo un oggetto Recordset
e inviamo la query attraverso
il metodo Open() */
$rs= new COM("ADODB.Recordset") ;
$rs->Open($query,$cn) ;
/* Ciclo per recuperare i valori dal recordset
EOF= tutto il set di dati è stato esaminato
e il cursore è giunto in fondo */
if (!$rs->EOF) {
// looping through all results
// products node
$response["tabripa"] = array();
while (!$rs->EOF) {
// temp user array
$product = array();
$product["pid"] = $rs -> Fields["Nbusta"]->value;
$product["name"] = $rs -> Fields["costo"]->value;
// $product["price"] = $rs -> Fields["costo"]->value;
// $product["description"] = $rs -> Fields["descrizione"];
// $product["created_at"] = $row["created_at"];
// $product["updated_at"] = $row["updated_at"];
$rs -> MoveNext();
// push single product into final response array
array_push($response["tabripa"], $product);
}
// success
$response["success"] = 1;
// echoing JSON response
echo json_encode($response);
} else {
// no products found
$response["success"] = 0;
$response["message"] = "No products found";
// echo no users JSON
echo json_encode($response);
}
/* Chiusura Recordset (da non farsi nelle query di comando) */
$rs->Close() ;
/* Pulizia dell’oggetto Recordset */
//$rs->Release() ;
//$rs= null ;
?>
Questo è la parte finale del Log cat
[ 09-12 11:27:42.268 14052:14052 D/ ]
HostConnection::get() New Host Connection established 0xaa9ee910, tid 14052
09-12 11:29:06.125 14052-15311/com.example.androidhive D/All Products:: {"tabripa":[{"pid":71754,"name":58088},{"pid":72262,"name":0},{"pid":74786,"name":174264},{"pid":56477,"name":3873},{"pid":74949,"name":0},{"pid":58359,"name":7745},{"pid":76441,"name":0},{"pid":68551,"name":7745},{"pid":69208,"name":25172},{"pid":70113,"name":15490},{"pid":79740,"name":1936},{"pid":100082,"name":0},{"pid":80022,"name":5809},{"pid":79980,"name":58088},{"pid":80806,"name":1936},{"pid":100448,"name":9681},{"pid":81464,"name":7745},{"pid":100704,"name":0}],"success":1}
09-12 11:29:06.125 14052-15311/com.example.androidhive W/System.err: org.json.JSONException: No value for products
09-12 11:29:06.125 14052-15311/com.example.androidhive W/System.err: at org.json.JSONObject.get(JSONObject.java:389)
09-12 11:29:06.125 14052-15311/com.example.androidhive W/System.err: at org.json.JSONObject.getJSONArray(JSONObject.java:584)
09-12 11:29:06.125 14052-15311/com.example.androidhive W/System.err: at com.example.androidhive.AllProductsActivity$LoadAllProducts.doInBackground(AllProductsActivity.java:139)
09-12 11:29:06.125 14052-15311/com.example.androidhive W/System.err: at com.example.androidhive.AllProductsActivity$LoadAllProducts.doInBackground(AllProductsActivity.java:105)
09-12 11:29:06.125 14052-15311/com.example.androidhive W/System.err: at android.os.AsyncTask$2.call(AsyncTask.java:295)
09-12 11:29:06.125 14052-15311/com.example.androidhive W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:237)
09-12 11:29:06.125 14052-15311/com.example.androidhive W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
09-12 11:29:06.125 14052-15311/com.example.androidhive W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
09-12 11:29:06.125 14052-15311/com.example.androidhive W/System.err: at java.lang.Thread.run(Thread.java:818)
09-12 11:29:07.042 14052-14052/com.example.androidhive D/gralloc_ranchu: gralloc_unregister_buffer: exiting HostConnection (is buffer-handling thread)
[ 09-12 11:29:07.091 14052:14052 D/ ]
HostConnection::get() New Host Connection established 0xafe8aae0, tid 14052
09-12 11:29:07.094 14052-14052/com.example.androidhive D/gralloc_ranchu: gralloc_unregister_buffer: exiting HostConnection (is buffer-handling thread)
09-12 11:29:07.109 14052-14052/com.example.androidhive D/gralloc_ranchu: gralloc_unregister_buffer: exiting HostConnection (is buffer-handling thread)
[ 09-12 11:29:07.114 14052:14052 D/ ]
HostConnection::get() New Host Connection established 0xafe8aae0, tid 14052
09-12 11:29:07.133 14052-14052/com.example.androidhive D/gralloc_ranchu: gralloc_unregister_buffer: exiting HostConnection (is buffer-handling thread)
non vedo errori,fa per caricare i dati però la lista è vuota.