What is the best way to mock a static method using Mockito?

Both approaches are great, but to add to what @vindhya.rddy and @macy-davis mentioned:

While Mockito’s inline mock maker is the preferred and modern solution (and I recommend going with that if possible), PowerMockito can still be useful in legacy projects or situations where upgrading Mockito isn’t feasible.

Just a small note on mock validation—if you need to validate the parameters that are passed into DriverManager.getConnection, you can use verify() to ensure the right parameters are used. In Mockito, it’s straightforward with the inline mock maker, and I would always suggest trying to stick with the most modern tools when possible.