且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Spring数据源和数据库架构

更新时间:2022-10-20 17:25:12

问题是没有标准的方式来设置模式,每个数据库都有不同的机制



一个工作是将模式设置为db url的一部分...



对于db2该URL将如下所示:


 jdbc:db2:// SERVER_NAME:PORT / DATABASE:currentSchema = SCHEMA_NAME; pre> 

希望有帮助...



特别说明:确保你加分号在网址的末尾,否则您会收到错误,表示网址无效。还要确保没有最后一个;存在(甚至没有空格)。


I am trying to declare a Spring datasource pointing to a DB2 database. Presently I am using a org.springframework.jdbc.datasource.DriverManagerDataSource to setup the connection but am not finding any way to specify the database schema in the database in the datasource bean. Could anyone help me on this?

Problem is there is no standard way to set the schema, each database has a different mechanism.

A work around is to set the schema as part of the db url...

For db2 the url will look something like:

jdbc:db2://SERVER_NAME:PORT/DATABASE:currentSchema=SCHEMA_NAME;

hope that helps...

Special note: make sure you add the semicolon ; at the end of the URL, otherwise you will get errors saying URL is invalid. Also make sure nothing after last ; exists (not even spaces).