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

Answer

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)

Leave a Reply

Your email address will not be published. Required fields are marked *