Spring 数据源和数据库模式 [英] Spring Datasource and Database Schema

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

问题描述

我正在尝试声明一个指向 DB2 数据库的 Spring 数据源.目前我正在使用 org.springframework.jdbc.datasource.DriverManagerDataSource 来设置连接,但没有找到任何方法来在数据源 bean 的数据库中指定数据库模式.谁能帮我解决这个问题?

解决方案

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

解决方法是将架构设置为 db url 的一部分...

对于 db2,url 看起来像:

<块引用>

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

希望对您有所帮助...

特别注意:一定要加分号;在 URL 的末尾,否则你会得到错误,说 URL 无效.最后还要确保什么都没有;存在(甚至没有空格).

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天全站免登陆