gpt4 book ai didi

java - Spring jdbc 中使用的查询转换为 db2

转载 作者:太空宇宙 更新时间:2023-11-04 06:28:52 24 4
gpt4 key购买 nike

我对 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 将是“值”引号内的字符串实体。我尝试通过连接到数据库测试副本的 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 是使用 Spring 控制反转容器管理的 java 类。 xml 文件中的信息定义了 Spring 初始化类时相关 Java Bean 使用的几个属性。在您的 XML 文件中,类代码中的 Java bean 似乎引用了属性“insertNotificationPreferenceSql”。 JDBCTemplate 类实际上运行 SQL,但需要研究 Java Bean 代码以了解该属性的实际使用情况。

关于java - Spring jdbc 中使用的查询转换为 db2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26409130/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com