0
try {
Connection lig = DriverManager.getConnection(
"jdbc:mysql://localhost/gym", "root", "0000");
PreparedStatement inst = lig
.prepareStatement("SELECT ph.Produtos_idProdutos, ph.Historico_idHistorico, p.Nome, p.Price "
+ "FROM produtos_has_historico ph "
+ "JOIN produtos p "
+ "ON p.idProdutos=ph.Produtos_idProdutos");
ResultSet rs = inst.executeQuery();
DefaultTableModel model = (DefaultTableModel) tableHistorico
.getModel();
model.setNumRows(0);
while (rs.next()) {
Object novaLinha[] = { rs.getInt("ph.Historico_idHistorico"),
rs.getInt("ph.Produtos_idProdutos"),
rs.getString("p.Nome"), rs.getDouble("p.Price") };
model.addRow(novaLinha);
}
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
CardLayout card = (CardLayout) frame.getContentPane().getLayout();
card.show(frame.getContentPane(), "Histórico");
This is the code I use to add to my table, the products. But I can also see products from other users, I don’t know if I have to change anything in the database. Thanks for the help.
What exactly is your question? The SQL command is bringing more stuff than it should, that’s it?
– Victor Stafusa
In your table do you have a column that indicates who the user is that has that history ? Something like Ph.usuario_id ? If so, just add the WHERE clause to your query... WHERE Ph.usuario_id = " + current user_code
– Guilherme Branco Stracini