0
I need help for my dao structure, as I call the connection, how I select within the function and how I list in my main the information coming from select.
As it is so far:
Connection to the bank.
package Modal;
import java.sql.Connection;
import java.sql.DriverManager;
public class ConexaoDB {
Connection conexao = null;
String driverDB = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
String rotaDB = "jdbc:sqlserver//10.0.0.14:1433;databasename=dbteste;user=db;password=123";
public boolean ConectarDB(){
try{
Class.forName(driverDB);
conexao = DriverManager.getConnection(rotaDB);
return true;
} catch (Exception e) {
System.out.println("Erro: Não foi possível se conectar ao banco de dados" + e.getMessage());
}
}
return false;
}
Modal
package Modal;
public class Tarefas {
public String NrPlaca;
public String getNrPlaca() {
return NrPlaca;
}
public void setNrPlaca(String nrPlaca) {
NrPlaca = nrPlaca;
}
}
Controller
package Cotroller;
import Dao.TarefasDao;
import Modal.Tarefas;
public class ControlTarefa {
public void ListaTarefas(){
Tarefas t = new Tarefas();
TarefasDao tarefasdao = new TarefasDao();
tarefasdao.ListaTarefas(t);
}
}
dao
package Dao;
import Modal.Tarefas;
public class TarefasDao {
public void ListaTarefas(Tarefas t){
//chamar conexao com o banco
//select
}
}
Got it, I don’t move much with java can show me how to send this data to the view, an example ?
– KevinF
What kind of view do you have? JSP, swing, fxml?
– Zulian
View is JSP type
– KevinF
You pass your controller through the method
setAttribute
of the interfaceServletRequest
, and then access via JSP like this:${tarefa.getNrPlaca}
. But that still depends on many factors, will use spring? If not, how well do you know aboutServletRequest
? Already have the views created? This part is more complex, maybe it is the subject of another question.– Zulian
Okay, I’ll see if I can ask another question about that.
– KevinF