MySQL connection validity test in datasource : SELECT 1 or something better?

前端 未结 2 472
庸人自扰
庸人自扰 2021-01-04 10:20

I\'m setting up a failover cluster on MySQL, in a master/slave architecture. I\'m also configuring my JBoss Datasource, and I\'m looking for the better way to test my connec

2条回答
  •  死守一世寂寞
    2021-01-04 10:38

    Quoting this link: Ping MySQL Server Using JDBC

    you have to:

    The MySQL JDBC driver (Connector/J) provides a ping mechanism.

    If you do a SQL query prepended with /* ping */ such as:

    "/* ping */ SELECT 1" This will actually cause the driver send a ping to the server and return a fake, light-weight, result set.

    (You can find this buried fairly deep in the Connector/J documentation; search for "ping" on that page. Read it carefully: this mechanism is very sensitive to the syntax used. Unlike most SQL, the "parsing" of the "ping" marker happens in the client-side JDBC driver itself.).

提交回复
热议问题