天天看點

java連接配接mysql資料庫連通性判斷

Connection connection = null;
try {
    Class.forName("com.mysql.jdbc.Driver");
    connection = DriverManager.getConnection(
            ds.getJdbcConnection(),
            ak.getAccessId(),
            ak.getAccessKey()
    );
    return connection.isValid(10);
} catch (ClassNotFoundException e) {
    return false;
}