gpt4 book ai didi

java - Commons DBUtils Oracle 11g 准备语句

转载 作者:行者123 更新时间:2023-11-30 03:05:12 25 4
gpt4 key购买 nike

我使用的是 oracle 数据库 11g 第 2 版,并且使用的是 apache commons dbutils v1.6、JDK 8 和 tomcat 8.0.30。所以我使用 QueryRunner 及其方法,如果我只是像这样在文本中连接我的变量,一切都会正常工作

query.query ("select * from table where field = '"+value+"'", rsh);

最近我一直在尝试使用准备好的语句以正确的方式进行查询,但每次我使用查询方法绑定(bind)参数时都无济于事

query.query ("select ESTREC,LOTE,FECREC from prueba.RECAUDO_ENC where NITREC = ? and ESTREC = ? ORDER BY FECREC DESC", rsh, new Object[]{"1234","PG"}); 

我无缘无故地收到此错误

java.sql.SQLException: ORA-00942: table or view does not exist
Query: select ESTREC,LOTE,FECREC from prueba.RECAUDO_ENC where NITREC = ? and ESTREC = ? ORDER BY FECREC DESC; Parameters: [1234, PG]

我 100% 确定该表存在,并且用户拥有该表的权限,而且如果我执行相同的查询,连接查询中的参数,它运行得很好,所以我正在寻找这种行为背后的原因,是否存在该方法的使用有什么问题吗?我还在某处读到,使用 dbutils 与 Oracle 进行 BLOB 绑定(bind)存在一些问题,这可能以某种方式相关吗?

最佳答案

oracle 的正确查询语法是:

query.query ("select ESTREC,LOTE,FECREC 
from prueba.RECAUDO_ENC
where NITREC = :P1 and ESTREC = :P2
ORDER BY FECREC DESC",
rsh, new Object[]{"1234","PG"});

关于java - Commons DBUtils Oracle 11g 准备语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34980461/

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