Spring数据源和数据库架构 [英] Spring Datasource and Database Schema

查看:141
本文介绍了Spring数据源和数据库架构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试声明一个指向DB2数据库的Spring数据源。目前我正在使用一个org.springframework.jdbc.datasource.DriverManagerDataSource来设置连接,但是我没有找到任何方法来指定数据源bean中的数据库模式。有人可以帮助我吗?

解决方案

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



一个工作是将模式设置为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).

这篇关于Spring数据源和数据库架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆