Carregar um Combobox pelo GWT RPC

1 resposta
A

Ola pessoal!!!

Estou com dificuldades para realizar uma operação na qual utilizando o GWT e estou tentando realizar uma conexão ao banco em MYSQL e por meio do RPC assim buscar um campo e carregar em um Combobox.
Segue abaixo os métodos que estou utilizando:

Classe que utilizo para realizar a conexão com o banco na qual ja esta funcionando para os recursos de validação e gravação.

import java.sql.*;
import javax.swing.*;

public class conexao {
    
    
    String driver = "com.mysql.jdbc.Driver";
    String url = "jdbc:mysql://localhost/android";
    String usuario = "root";
    String senha = "";
    
    private Connection conexao;
    public Statement statement;
    public ResultSet resultset;
    
    public boolean conecta(String driver, String url, String usuario, String senha, String banco)
    {
        boolean result = true;
        try
        {
            Class.forName(driver);
            conexao = DriverManager.getConnection(url, usuario, senha);
        }
        catch (ClassNotFoundException Driver)
                {
                    result = false;
                }
        catch (SQLException Fonte)
        {
            result = false;
        }
        return result;
    }
    public boolean conecta()
    {
        boolean result = true;
        try
        {
            Class.forName(driver);
            conexao = DriverManager.getConnection(url, usuario, senha);
            statement = conexao.createStatement();
        }
        catch (ClassNotFoundException Driver)
                {
                    result = false;
                }
        catch (SQLException Fonte)
        {
            result = false;
        }
        return result;
        }
    public void desconecta()
    {
        boolean result = true;
        try
        {
            conexao.close();
        }
        catch(SQLException fecha)
        {
            result = false;
        }
    }
    
    public void executaSQL(String sql)
    {
        try
        {
            statement = conexao.createStatement();
            resultset = statement.executeQuery(sql);
        }
        catch(SQLException sqlex){
    }
    
    }
}

Interface

import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
import java.util.List;

@RemoteServiceRelativePath("stacknotarpc")
public interface StackNotaInterface extends RemoteService {
    List<String> getTasks();
}

Interface Async

import com.google.gwt.user.client.rpc.AsyncCallback;
import java.util.List;

public interface StackNotaInterfaceAsync {
    void getTasks(AsyncCallback<List<String>> callback);
}

Interface Impl

import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import org.yournamehere.client.notas.NotaInterface;
import org.yournamehere.client.principal.StackNotaInterface;
import org.yournamehere.server.utilitarios.conexao;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import org.yournamehere.client.principal.menuStack;
import org.yournamehere.client.principal.Task;

public class StackNotaInterfaceImpl extends RemoteServiceServlet implements StackNotaInterface {
    
    
@Override
    public List<String> getTasks(){
        List<String> tasks = new ArrayList<String>();
 return conexao(tasks);
}
    
    conexao buscaLista;
    public List conexao(List tasks){
        try {
            buscaLista = new conexao();
            buscaLista.conecta();
            String sql = "select diciplina from notas "; // where diciplina = '" + diciplina + "'";
            buscaLista.statement.executeQuery(sql);
            } catch (Exception erro) {
                erro.getMessage();
        }
        return tasks;
    }
}

Tela onde esta o Combobox

...
final ComboBoxItem selectItem2 = new ComboBoxItem();
        selectItem2.setLeft(6);
        selectItem2.setTop(17);
        selectItem2.setTitle("Selecione");
        selectItem2.setHint("<nobr>Selecione a diciplina</nobr>");
        
        final AsyncCallback<List<String>> callback = new AsyncCallback< List<String>>() {

            @Override
           public void onSuccess (List<String> tasks){
               for(String task : tasks){
        selectItem2.setDefaultValue(tasks);
                      }
           }
           
	public void onFailure(Throwable caught) {
		caught.getMessage();
	}
};
        CanvasItem canvasItem = new CanvasItem("newCanvasItem_2", "New CanvasItem");
        canvasItem.setLeft(32);
        canvasItem.setTop(125);
...

Se alguem pode-se me ajudar seria de grande apoio.

Obrigado!

1 Resposta

E

Bom dia. Amigo estou com esse mesmo problema. você conseguiu resolver o seu? obrigado.

Criado 25 de outubro de 2012
Ultima resposta 23 de out. de 2013
Respostas 1
Participantes 2