Java JDBC connection status

前端 未结 6 1263
太阳男子
太阳男子 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:28

    You also can use

    public  boolean isDbConnected(con Connection) {
        //final String CHECK_SQL_QUERY = "SELECT 1";
        try {
            if(!con.isClosed() || con!=null){
                return true;
            }
        } catch (SQLException e) {
            return false;
        }
        return false;
    }
    

提交回复
热议问题