Java JDBC connection status

前端 未结 6 1264
太阳男子
太阳男子 2020-12-02 19:52

I am (successfully) connecting to a database using the following:

java.sql.Connection connect = DriverManager.getConnection(
  \"jdbc:mysql://localhost/some_         


        
6条回答
  •  时光说笑
    2020-12-02 20:41

    The low-cost method, regardless of the vendor implementation, would be to select something from the process memory or the server memory, like the DB version or the name of the current database. IsClosed is very poorly implemented.

    Example:

    java.sql.Connection conn = ;
    conn.close();
    try {
      conn.getMetaData();
    } catch (Exception e) {
      System.out.println("Connection is closed");
    }
    

提交回复
热议问题