Click here to Skip to main content
15,889,808 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi guys,

I have a database connection and a Jtable in eclipse. Every time I click on the button the Jtable will be updated with the new information in the database. The problem is every time I click on the button the same data is printed, but I just wanted to print the datasets which are new in the database.

y {
    java.sql.Connection con = DriverManager.getConnection ("jdbc:mysql://localhost:3306/test","root",""); 

    String query = "Select distinct * from test";
    Statement statement = (Statement) con.createStatement();
    ResultSet rs= statement.executeQuery(query);
    while(rs.next())
    {
        String name = rs.getString("name");
        String age= rs.getString("age");
        String number= rs.getString("number");
        model.addRow(new Object[]{name, age, number});
    }
        table.setModel(model);
}
catch(Exception e){
    JOptionPane.showMessageDialog(null, "failes");
}


What I have tried:

Tried a lot but nothing works...
Posted
Updated 6-Jun-18 20:52pm
Comments
Richard Deeming 6-Jun-18 12:46pm    
Your code is doing exactly what you've told it to do - select all records from the table, and display them.

If that's not what you want it to do, then you need to tell it to do something else - for example, add a WHERE clause to your query.

Since you haven't explained how you would identify "new" records, we can't tell you what filter you need to use.
Member 13814158 7-Jun-18 12:03pm    
I am SORRY
@Richard Deeming. Thank you so much for your answer. I have a UI in java and there I get in the JTable all the information from the database when I click on a button. But I just wanted to show the datasets which are new. This means when there are don't exist new datasets there would be no new output, just when there is a new dataset, it should only update the new one into the jTable. I hope that is not confusing :(

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900