I have a java program that returns the list of users who have a query on that day, so I built a database that lists some important data of the users, the name of the doctor with whom they will have a query and some such as the living room and the floor. For the SQL query to return only those queries that day I tried to JOIN the 3 tables + the join table with a WHERE so that it returns the queries that are scheduled for the day that is compared to the variable dataFinal (var from the Java program which gets the date in the format yyyy / MM / dd).
The problem is that this query is only returning a single user who has a query on that date, but there are more users who have the same dates associated and are not appearing.
Java:
public void componentShown(ComponentEvent arg0) {
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
Date date = new Date();
System.out.println(dateFormat.format(date));
String dataFinal = dateFormat.format(date);
try {
Connection lig = DriverManager.getConnection("jdbc:mysql://localhost/htmdb", "root", "");
PreparedStatement inst = lig
.prepareStatement(
"SELECT nome, sala_piso, nomeFuncionario, departamento, data, tempo, confirmacao FROM consulta "
+ "JOIN utentes ON consulta.utentes_utente_id = utentes.utente_id "
+ "JOIN funcionarios_has_consulta ON funcionarios_has_consulta.consulta_consulta_id = consulta.consulta_id "
+ "JOIN funcionarios ON funcionarios.funcionario_id = funcionarios_has_consulta.funcionarios_funcionario_id WHERE data ='"
+ dataFinal + "' ");
ResultSet rs = inst.executeQuery();
tableAgendadas.setModel(DbUtils.resultSetToTableModel(rs));
JOptionPane.showMessageDialog(frmHealthTreatmentManager, "Hoje é dia : " + dataFinal);
lig.close();
} catch (SQLException e1) {
JOptionPane.showMessageDialog(frmHealthTreatmentManager,
"Impossível ligar à base de dados. " + e1.getLocalizedMessage());
}
}
Iwanttogetthisresult: