0

I want to create a connection with root of mysql for access all databases.

Thanks in advance

0

1 Answer 1

0

Leaving aside that using the root account for something different than administrative purposes might be a bad idea ... well, still, you cannot connect to "all databases", at least not at once. What you can do is:

  • create a connection to one of the existing databases. (most likely use mysql for a start, as you can be sure this one exists)
  • if you need to point the connection to a different database, use the connection.setCatalog(String) method of the java.sql.Connection class to switch to a different database.

If you want to know which databases exist, see this question: how to get list of Databases "Schema" names of MySql using java JDBC

Sign up to request clarification or add additional context in comments.

2 Comments

How can I fetch all database name ?
Oops, I missed that , sorry and Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.