[英]conversion of query used in Spring jdbc to db2
我對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>
我認為普通的DB2格式的sql將是“值”引號中的字符串實體。 我嘗試通過連接到數據庫的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語句時遇到了問題; 我試圖稍微清理壓痕以使其有意義。 該語句看起來是將行插入到名為“ NOTIFICATION”的表中,其中ID字段有些混亂,這是從BCSACCT.CODE或BCSACCT.ACCTID上的一堆OR得出的,PERSONKY和INSTANCEKY相當簡單。
快速說明:Spring Bean是Java類,由“控制容器的Spring反轉”管理。 xml文件中的信息定義了Spring初始化類時相關Java Bean使用的幾個屬性。 在XML文件中,似乎Java類在類代碼中引用了屬性“ insertNotificationPreferenceSql”。 JDBCTemplate類實際上運行SQL,但是需要調查Java Bean代碼以查看該屬性的實際使用方式。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.