I needed to change database to query so i used setSchema()
method of Connection
object but it didn't work and i found setCatalog()
method and yes it worked.
Connection connection = dataSource.getConnection();
connection.setSchema(schema); // not working
connection.setCatalog(schema); // working
I found that in MySQL and probably in MariaDB as well the term catalog
and schema
means the same thing which is database in this case and there is connection parameters which term would activate such as NO_SCHEMA
and NO_CATALOG
.
I could see that those parameters are listed in this page so i thought there is similar page in MariaDB as well but still no luck.
I want to know what makes setCatalog()
works and setSchema()
doesn't. Please let me know if there is resource about it.
The option useCatalogTerm
exists in MariaDB as well. Documentation https://mariadb.com/kb/en/about-mariadb-connector-j/ was missing that option, and that is just corrected now.
Note that setting option useCatalogTerm to schema (i.e., connection string like jdbc:mariadb://host/db?useCatalogTerm=schema
) will not only add use of connection.setSchema(schema) in place of connection.setCatalog(schema) but will also impact metadata use: for example DatabaseMetaData.getSchemas(String catalog, String schemaPattern)