I need help to structure my dao, how do I call the connection, how do I select within the function, and how do I list in my main the information that comes from select.
As it is now:
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
}
}