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.
[code]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){
}
}
}[/code]
Interface
[code]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 getTasks();
}[/code]
Interface Async
[code]import com.google.gwt.user.client.rpc.AsyncCallback;
import java.util.List;
public interface StackNotaInterfaceAsync {
void getTasks(AsyncCallback<List> callback);
}[/code]
Interface Impl
[code]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 getTasks(){
List tasks = new ArrayList();
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;
}
}[/code]
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!