-1
I have a program in java that returns the list of users who have an appointment that day, for this I built a database that related some important data of the users, the name of the doctor with whom they will have an appointment and also some data as the room and the floor. In order for the SQL query to return only the queries of that day I tried to JOIN the 3 tables + the join table with a WHERE so that it only returns the queries that are scheduled for the day that is compared with the variable dataFinal (var of the Java program that gets the date in yyyy/MM/dd format).
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 associated dates 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());
}
}
I want to get this result:
I edited the question because "phpmyadmin" is not a "database", read this to understand the differences: What is the difference between mysql and phpmyadmin?
– Guilherme Nascimento