Ping一个MySQL服务器 [英] Ping a MySQL server

查看:118
本文介绍了Ping一个MySQL服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Java中是否有一个特定的方法来检查MySQL服务器是否还活着?

Is there a specific method in Java that checks whether a MySQL server is alive?

推荐答案

假设你正在运行在Java 6或更高版本中,您可以使用标准JDBC方法 Connection.isValid(int timeoutInSecs)。深入研究MySQL Connector / J源代码,实际实现使用com.mysql.jdbc.ConnectionImpl.pingInternal()将简单的ping数据包发送到DB,只要返回有效的响应,就返回true。

Assuming that you're running in Java 6 or higher, you can use the standard JDBC method Connection.isValid(int timeoutInSecs). Digging into the MySQL Connector/J source, the actual implementation uses com.mysql.jdbc.ConnectionImpl.pingInternal() to send a simple ping packet to the DB and returns true as long as a valid response is returned.

这篇关于Ping一个MySQL服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆