Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/", "user", "password"); connection.setCatalog("my_database");
String catalogName = "my_database"; Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/", "user", "password"); connection.setCatalog(catalogName);In this example, we set the catalog name to a variable that can be dynamically set at runtime. Package Library: java.sql