Java 如何在数组中从mysql检索结果?

Java 如何在数组中从mysql检索结果?,java,android,mysql,arrays,json,Java,Android,Mysql,Arrays,Json,我希望以数组的形式从数据库中获取结果。我有一张有存货的“commande”桌子。我想以数组的形式获取库存。类似这样的内容:array[0],array[],array[2] 这是我的表命令的结构(idfichecmd idproduit idclt qte datecmd) 这是我的代码: String response = null; String res = ""; //the year data to send ArrayList<NameValuePair> nameValu

我希望以数组的形式从数据库中获取结果。我有一张有存货的“commande”桌子。我想以数组的形式获取库存。类似这样的内容:
array[0],array[],array[2]
这是我的表命令的结构
(idfichecmd idproduit idclt qte datecmd)

这是我的代码:

String response = null;
String res = "";
//the year data to send
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("",));   
try {
    Log.i("","<<<<<<<<<<<<<<<<<<<<TRY");      
    response = CustomHttpClient.executeHttpPost("http://0.0.0.0/GetCmdDetails.php",nameValuePairs); 
    res=response.toString();
    // res = res.trim();
    //res= res.replaceAll("\\s+","");
    //error.setText(res);

} catch (Exception e) {
    Log.i("","<<<<<<<<<<<<<<<<<<<<Catch");
}

//parse json data
try{
    JSONArray jArray = new JSONArray(res);
    //-----------------------------------------
    //nom= new String[jArray.length()];
    //prenom= new String[jArray.length()];
    //----------------------------------------
    for (int i=0;i<jArray.length();i++) {
        JSONObject json_data = jArray.getJSONObject(i)
String响应=null;
字符串res=“”;
//要发送的年度数据
ArrayList nameValuePairs=新的ArrayList();
添加(新的BasicNameValuePair(“,”);
试一试{

Log.i(“,”首先,测试您的查询是否给出了正确的结果

我使用此解决方案获取jsonarray:

使用HttpClient调用Web服务

private List<NameValuePair> parameters;

    HttpClient httpClient = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost(//yoururl);
    int statusCode = -1;
    try {
        httpPost.setEntity(new UrlEncodedFormEntity(this.parameters));
        HttpResponse response = httpClient.execute(httpPost);
        statusCode = response.getStatusLine().getStatusCode();

 //Get your inputstream here and convert it to json after

    BufferedReader in = new BufferedReader
                        (new InputStreamReader(response.getEntity().getContent()));
私有列表参数;
HttpClient HttpClient=新的DefaultHttpClient();
HttpPost-HttpPost=newhttppost(//yoururl);
int statusCode=-1;
试一试{
setEntity(新的UrlEncodedFormEntity(this.parameters));
HttpResponse response=httpClient.execute(httpPost);
statusCode=response.getStatusLine().getStatusCode();
//在这里获取您的inputstream,然后将其转换为json
BufferedReader in=新的BufferedReader
(新的InputStreamReader(response.getEntity().getContent());

您在哪里指定了数据库连接?http post请求中返回了什么?只返回表中的第一个字段您可以发布实际返回的字符串和生成该字符串的代码吗?$sql=mysql\u query(“从命令中选择qte,其中idfichecmd='$id');$output=array();while($row=mysql\u fetch\u assoc($sql)){$output[]=$row;}print(json_encode($output));不,我可以得到结果,但我得到字段中的最后一个数字。对不起,我不知道这是什么意思。我在数据库中得到结果,问题是我如何在数组中得到结果,类似于这个数组[0],数组[1]…我在我的服务器上测试了您的PHP代码。我使用echo json_encode,我将echo更改为打印,但失败。尝试使用echo?在我的应用程序中,我有5个textview,我想从返回结果中加载它每个数字代表一个textview