I designed a jTable that will display data from a table in MySql DB.

The table name is `studentrolls` with `STRollID` (int) as primary key and `StudentID` (Varchar), `BachID` (year) as foreign keys.

So after typing the `StudentID` in a jTextField and clicking a jButton only data concerning the student should be displayed in the jTable.

It's working actually but am having two problems, instead of displaying the Year on the year column it's displaying a date for example it should display 2020 but it displaying 2020-01-01.

The main problem is that when I enter another `StudentID`, it is adding the new results to the old one, so when I enter for the first time a `StudentID` I get good results and then when I enter another `StudentID` and click the button I get in the table the new results mixed with the first student's one, etc...

Is there any way to solve this and clear the table before inserting new results?

Here is my code :

```
private void rSButtonIconDsearchstidActionPerformed(java.awt.event.ActionEvent evt) {
     try{
        String sqlqueryPastYHi = "SELECT * FROM studentrolls WHERE StudentID = ? ORDER BY BachID";
        PreparedStatement preparedStatement = con.prepareStatement(sqlqueryPastYHi);
        PreparedStatement  pst=con.prepareStatement(sqlqueryPastYHi);

        if(!jTextFieldsearchstid.getText().isEmpty() ) {
            preparedStatement.setString(1, jTextFieldsearchstid.getText());
            ResultSet resultSet = preparedStatement.executeQuery();

            while(resultSet.next()){
                String scolaryear = resultSet.getString("BachID");
                String stclass = resultSet.getString("ClassID");
                String totpercent = String.valueOf(resultSet.getInt("PourcentTotal"));
                String finalplace = String.valueOf(resultSet.getInt("PlaceFinale"));
                String appication = resultSet.getString("Aplication");
                String behavior = resultSet.getString("Conduite");
                String finalaction = resultSet.getString("ActionFinale");

                String pastHistTableData [] = {scolaryear, stclass, totpercent, finalplace, appication, behavior, finalaction};
                DefaultTableModel tblModel = (DefaultTableModel)jTablehipastyears.getModel();
                tblModel.addRow(pastHistTableData);
            }
        } 
        else{
            JOptionPane.showMessageDialog(this, "Veillez taper le matricule d'un eleve svp.");
        }
    }catch (Exception exception){
        JOptionPane.showMessageDialog(this, "erreur des donnees: " + exception.getMessage());
    } 
}

```