我需要更改数据库来查询,所以我使用了
setSchema()
对象的 Connection
方法,但它不起作用,我找到了 setCatalog()
方法,是的,它起作用了。
Connection connection = dataSource.getConnection();
connection.setSchema(schema); // not working
connection.setCatalog(schema); // working
我发现在 MySQL 中,可能在 MariaDB 中,术语
catalog
和 schema
表示相同的事物,在本例中是数据库,并且有术语会激活的连接参数,例如 NO_SCHEMA
和 NO_CATALOG
。
我可以看到这些参数列在this页面中,所以我认为MariaDB中也有类似的页面,但仍然没有运气。
我想知道是什么让
setCatalog()
起作用而 setSchema()
不起作用。如果有相关资源请告诉我。
选项
useCatalogTerm
也存在于 MariaDB 中。文档 https://mariadb.com/kb/en/about-mariadb-connector-j/ 缺少该选项,现在刚刚更正。
请注意,将选项 useCatalogTerm 设置为 schema(即像
jdbc:mariadb://host/db?useCatalogTerm=schema
这样的连接字符串)不仅会添加使用 connection.setSchema(schema) 来代替 connection.setCatalog(schema),而且还会影响元数据的使用:例如 DatabaseMetaData.getSchemas(String catalog, String schemaPattern)