I am completely new to spring jdbc, I came across a situation where I need to convert sql used in spring jdbc configuration file to plain db2 format. For example below is the query used (inside value tag) in the spring conf file, which I want to change to run against db2 i browse many spring documentation but failed to find any relative information, can someone point me to the link or the solution to this sql formatting
<?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>
I think the plain DB2 formated sql would be the string entity within your "value" quotes. I try running the exact same query through a SQL client connected to a TEST copy of the database and see if you get the results you are looking for.
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**
)
You might be having problems with the SQL statement; I tried to clean the indentation up a bit to make sense of it. This statement looks to insert rows into a table called "NOTIFICATION", where the ID field is some a mess figured out from a mess of ORs on the BCSACCT.CODE or BCSACCT.ACCTID, the PERSONKY and INSTANCEKY are pretty straight forward.
Quick explanation: Spring Beans are java classes that are managed with the Spring Inversion of Control Container. Information in your xml file defines several properties that the related Java Bean uses when the class is initialized by Spring. In your XML file, it appears that the property "insertNotificationPreferenceSql" is referenced by the Java bean in the class code. The JDBCTemplate class actually runs the SQL, but the Java Bean code needs to be investigated to see how that property is actually being used.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.