0

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

Thanks in advance

1 Answers1

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

Community
  • 1
  • 1
Clemens Klein-Robbenhaar
  • 3,457
  • 1
  • 18
  • 27