我对spring jdbc完全不熟悉,我遇到了一种情况,我需要将spring jdbc配置文件中使用的sql转换为纯db2格式。 例如,下面是spring conf文件中使用的查询(内部值标记),我想更改为针对db2运行 我浏览了许多spring文档,但未能找到任何相关信息,有人可以指向我链接或这个sql格式的解决方案
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<!-- JNDI DataSource for J2EE environment. -->
<bean id="mi.conv.batch.dataSource" class="org.springframework.jdbc.datasource.WebSphereDataSourceAdapter">
<property name="targetDataSource">
<jee:jndi-lookup id="dataSourceInternal" jndi-name="java:comp/env/jdbc/Database" />
</property>
</bean>
<!-- Transaction manager that delegates to JTA (use it when running within a container) -->
<bean id="mi.conv.batch.TransactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"/>
<!-- Transactional proxy for data access facade. -->
<bean id="mi.conv.batch.transactionProxyParent" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" abstract="true">
<property name="transactionManager" ref="x.y.z.TransactionManager"/>
<property name="transactionAttributes">
<props>
<prop key="add*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<bean id="statementsDao" parent="x.y.z.transactionProxyParent">
<property name="target">
<bean class="abc.test.TestDaoImpl">
<property name="dataSource" ref="a.b.c.dataSource"/>
<property name="insertNotificationPreferenceSql">
<value>
select
NOTIFICATIONKY
from new table (
insert into
NOTIFICATION (
ID,
PERSONKY,
INSTANCEKY
)
**select
(substr( ba.CODE, 1, 2 ) || '1111' || RIGHT( ba.CODE, 4 ) ||
(case substr( ba.CODE, 1, 2 )
when 'XY' then ''
else '2222'
end)
|| '0000' || ba.ACCTID ) as ID,
cp.PERSONKY,
ba.INSTANCEKY
from
BCSACCT ba
join
PERSON cp on ( 1=1 )
where cp.PERSONKY = :personId
and ba.INSTANCEKY = :prodinstId**
)
</value>
</property>
</bean>
</property>
</bean>
</beans>
答案 0 :(得分:1)
我认为普通的DB2格式化sql将是你的&#34;值&#34;中的字符串实体。引号。我尝试通过连接到数据库的TEST副本的SQL客户端运行完全相同的查询,看看你是否得到了你正在寻找的结果。
select NOTIFICATIONKY
from new table (
insert into NOTIFICATION (
ID,
PERSONKY,
INSTANCEKY
)
**select ( substr( ba.CODE, 1, 2 ) ||
'1111' ||
RIGHT( ba.CODE, 4 ) ||
(case substr( ba.CODE, 1, 2 ) when 'XY' then '' else '2222' end) ||
'0000' ||
ba.ACCTID ) as ID,
cp.PERSONKY,
ba.INSTANCEKY
from BCSACCT ba
join PERSON cp on ( 1=1 )
where cp.PERSONKY = :personId
and ba.INSTANCEKY = :prodinstId**
)
您可能遇到SQL语句问题;我试着稍微清理缩进以理解它。这个语句看起来将行插入名为&#34; NOTIFICATION&#34;的表中,其中ID字段是从BCSACCT.CODE或BCSACCT.ACCTID上的一堆OR中弄清楚的,PERSONKY和INSTANCEKY很漂亮直截了当。
快速解释: Spring Beans是使用Spring Inversion of Control Container管理的java类。 xml文件中的信息定义了Spring在初始化类时相关Java Bean使用的几个属性。在您的XML文件中,似乎属性&#34; insertNotificationPreferenceSql&#34;在类代码中由Java bean引用。 JDBCTemplate类实际上运行SQL,但需要调查Java Bean代码以查看该属性的实际使用方式。