Ideas to make a private history

Asked

Viewed 45 times

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.

  • 1

    What exactly is your question? The SQL command is bringing more stuff than it should, that’s it?

  • 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

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.