Logo
Published on

Simple JDBC connection test

Authors

There is no easier way to test a jdbc connection, here using a mysql database

import java.sql.Connection;
import java.sql.DriverManager;

try {
    Class.forName("com.mysql.jdbc.Driver");

    String url = "jdbc:mysql://localhost:3306/mybd";
    Connection con = DriverManager.getConnection(url, "admin", "");
    if( con.isClosed() ) {
        System.out.println("Connexion fermée");
    } else {
        System.out.println("Connexion ouverte");
        con.close();
    }
} catch(Throwable t) {
        System.err.print(t.getMessage());
        t.printStackTrace(System.err);
}