Database query with java

Asked

Viewed 65 times

-2

I will make a comparison with my problem using a database functionality and html Jquery.

With Jquery we have the possibility to visit the database and bring the data to the frontend in HTML, and this can be done constantly without influencing the user interface (HTML) or that everything stops until the query is performed.

My problem in java is that I have a Jtable and its data is taken from a database and the consulted table is constantly changing, with new data being entered and I need Jtable to support these changes.

Is there any way or something that makes this possible?

1 answer

0


I don’t know if I understand correctly what your question is, but if you are simply updating a Jtable’s data, just do a new query in the database and pass the result to Jtable. As an example I have the code snippet of a project of mine that uses the MVC standard.

//método para listar os alunos que atuam como monitores de disciplinas
public void listar(String str){
    //instancio um objeto que me permita fazer consulta no banco de dados
    MonitorDAO dao = new MonitorDAO();
    //realizo a consulta e coloco o resultado num ArrayList
    monitores = dao.consultaMonitores(str);
    //seto para a JTable um novo TableModel que vai receber o resultado da consulta anterior
    tela.getTabela().setModel(new MonitorTableModel(monitores));
}

Having this method, I call you whenever it is necessary to update Jtable’s data.

Browser other questions tagged

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