Search code examples
javaeclipsetomcat9

How to check that our Database is connected in java dynamic project in eclipse?


I used an eclipse java dynamic project I want to know that my database is connected or is that working properly I used the xampp apache server and tomcat 9


Solution

  • you can use this usefull method from the java.​sql.​Connection Class:

    
    Connection con = new Connection(/* MY SERVER PARAMETERS */);
    
    boolean valid=con.isValid(/* int millis */);
    System.out.println("The connection is active?" + valid);
    
    

    Hope this link can help you: https://docs.oracle.com/javase/7/docs/api/java/sql/Connection.html#isValid(int)