问题创建一个类SQL Query Studio Android

时间:2016-10-06 15:18:35

标签: android android-studio

今天我的问题是开发了一个具有登录,维护产品的APP(更多的说法),所有这些都是使用数据库引擎SQL

并创建登录全部确定,程序正常登录用户并通过以前,也认为维护创建产品,我将产品的名称及其各自的描述作为参数,我添加,编辑和删除,只是没有管理搜索数据,并在访问相应的布局时显示我,使用我的MainMenu的onCreate方法,但嘿,情况并非如此,相关的情况是我想通过一个按钮知道如何做到这一点,找到我在EditText上输入的名称或与名称相关的名称,并尝试使用以下代码执行此操作:

package com.sqldata.gst.appsql;

import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.SimpleAdapter;
import android.widget.Toast;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;


/**
 * Created by Administrador on 05/10/2016.
 */

public class ConClientes extends MainActivity {
    Conexion conexionSQL;
    EditText txtCdCliente, txtNomCli;
    Button btnBuscar, btnRetornar;
    ProgressBar pgrCliente;
    ListView lstClientes;
    String idCliente;
    //ResultSet rs;

    @Override
    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.con_clientes);

        conexionSQL = new Conexion();
        txtCdCliente = (EditText) findViewById(R.id.txtCdCliente);
        //txtNomCli = (EditText) findViewById(R.id.txtNomCli);
        btnBuscar = (Button) findViewById(R.id.btnBuscar);
        btnRetornar = (Button) findViewById(R.id.btnRetornar);
        pgrCliente = (ProgressBar) findViewById(R.id.pgrCliente);
        lstClientes = (ListView) findViewById(R.id.lstClientes);
        pgrCliente.setVisibility(View.GONE);
        idCliente = "";

        // Evento Ejecutar Boton
        btnBuscar.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SelectClientes selectClientes = new SelectClientes();
                selectClientes.execute(""); //Cannot resolve method 'execute(java.lang.String)
            }
        });
    }

    public class FillList extends AsyncTask<String, String, String>
    {
        String result = "";

        List<Map<String, String>> CliList = new ArrayList<Map<String, String>>();

        @Override
        protected void onPreExecute(){
            pgrCliente.setVisibility(View.VISIBLE);
        }

        @Override
        protected void onPostExecute(String r){
            pgrCliente.setVisibility(View.GONE);
            Toast.makeText(ConClientes.this, r, Toast.LENGTH_SHORT).show();

            String[] from = {"A", "B", "C"};
            int[] views = {R.id.lblClienteId, R.id.lblNomCli, R.id.lblCodCli};
            final SimpleAdapter ADA = new SimpleAdapter(ConClientes.this, CliList, R.layout.lst_cliente,
                    from, views);
            lstClientes.setAdapter(ADA);

            lstClientes.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                    HashMap<String, Object> obj = (HashMap<String, Object>) ADA.getItem(arg2);
                    idCliente = (String) obj.get("A");
                    //String ClienName = (String) obj.get("B");
                    String ClienCod = (String) obj.get("C");
                    //txtNomCli.setText(ClienName);
                    txtCdCliente.setText(ClienCod);

                }
            });
        }

        @Override
        protected String doInBackground (String... params){
            try{
                Connection cnSQL = conexionSQL.CONN();
                if (cnSQL == null){
                    result = "Error en la Conexión SQL Server";
                }
                else{
                    String query = "select * from clientes";
                    PreparedStatement psSQL = cnSQL.prepareStatement(query);
                    ResultSet rsSQL = psSQL.executeQuery();

                    ArrayList data1 = new ArrayList();
                    while (rsSQL.next()){
                        Map<String, String> dataRec = new HashMap<String, String>();
                        dataRec.put("A", rsSQL.getString("idcliente"));
                        dataRec.put("B", rsSQL.getString("nom_cli"));
                        dataRec.put("C", rsSQL.getString("cod_cli"));
                        CliList.add(dataRec);
                    }
                    result = "Success";
                }
            } catch (Exception ex){
                result = "Error al Buscar Datos de la Tabla Clientes";
            }
            return result;
        }
    }

    public class SelectClientes extends ArrayList<String>{

        String result = "";
        Boolean isSuccess = false;

        String ClienCod = txtCdCliente.getText().toString();
        String NomCli = txtNomCli.getText().toString();

        @Override //Method does not override method from its superclass
        protected void onPreExecute(){
            pgrCliente.setVisibility(View.VISIBLE);
        }

        //@Override
        protected void onPostExecute(String r){
            pgrCliente.setVisibility(View.GONE);
            Toast.makeText(ConClientes.this, r, Toast.LENGTH_SHORT).show();
            if (isSuccess == true){
                FillList fillList = new FillList();
                fillList.execute("");
            }
        }

        @Override //Method does not override method from its superclass
        protected String doInBackground(String... params){
            if (ClienCod.trim().equals(""))
                result = "Favor de Introducir el Codigo del Cliente";
            else {
                try{
                    Connection con = conexionSQL.CONN();
                    if (con == null){
                        result = "No Hay Datos para Mostrar";
                    } else {
                        String query = "Select * from clientes where idcliente =" + idCliente;
                        PreparedStatement preparedStatement = con.prepareStatement(query);
                        preparedStatement.executeUpdate();
                        result = "Busqueda de Datos Correcta";
                        isSuccess = true;
                    }
                } catch (Exception ex){
                    isSuccess = false;
                    result = "Verifique los Datos";
                }
            }
            return result;
        }


    }
}

观察到这是我的代码和尝试,但有两个因素是注释代码,第一个是:

selectClientes.execute(""); // Can not resolve method 'execute (java.lang.String)

和覆盖中的第二个

@Override //Method does not override method from its superclass

这是我的唠叨我不明白我怎么能让我查询包含editext =这将是寻求的名称,以及执行select * from的动作的按钮,你了解我

我想从菜单中输入布局时加载并显示数据,而不按任何内容

比如doInBackground方法,这就是我想要做的但是我想它在onCreate中你会理解我,如果你需要更多的细节,请说,我想要的是解决这个小问题

感谢All !!

1 个答案:

答案 0 :(得分:0)

当然app无法解析方法execute,因为ArrayList没有它。

SelectClientes extends ArrayList

SelectClientes应扩展AsyncTask