0

I am developing 2 application who are reliated to the same database. I use java swing and I want to update my Frame when the database is updated from the other application. I tried to write my code in a loop using

while (this.isVisible())

But it doesn't work. My code:

try
 { 
 Class.forName("com.mysql.jdbc.Driver");
 Connection con= DriverManager.getConnection("jdbc:mysql://localhost/Base", "root", "");
 PreparedStatement pstmt = con.prepareStatement("SELECT enter from table where person =? ");
 pstmt.setString(1,"responsable");
 ResultSet rs= pstmt.executeQuery();
 while (this.isVisible()){
 while(rs.next()){
 
 if (rs.getInt("enter")==0)
   {
     jLabel13.hide();
     jLabel10.setVisible(true);
   }
else
   {
     jLabel10.hide();
     jLabel13.setVisible(true);
    }}}
4
  • 1
    you should have a thread running in the background that checks for updates in your db
    – Stultuske
    Commented Mar 26, 2021 at 10:26
  • Try to debug and figure out what you are selecting. Listen to the database and display all new things. If applications have communication channels except a database-channel better to implement event-driven behavior. The 1-st app produces some events, let's say with a new record's ID inside. The second app consumes that event and fetches data from the database and displays it. Commented Mar 26, 2021 at 10:54
  • Are the 2 applications completely separate? Or is it say two JFrames in the same application?
    – gthanop
    Commented Mar 27, 2021 at 0:21
  • They are completely separate. the second one is a mobile application. Commented Mar 27, 2021 at 5:56

0

Browse other questions tagged or ask your own question.