gpt4 book ai didi

java - 预期位置参数计数 : 1, 实际参数:[]

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:59:25 24 4
gpt4 key购买 nike

当我尝试使用来自 DaoImpl 类的 HIbernate 执行存储过程时,出现以下异常。 我不确定出了什么问题..我尝试了所有方法来修复它但没有解决问题。 任何人都可以帮助我,找出代码或映射文件有什么问题。我尝试修复的越多,我得到的异常就越多。我正在连接到 Oracle 9i DB。我在这个问题上苦苦挣扎了 2 周,最终无处可去。任何人都可以帮我解决这个问题。

映射文件:

<hibernate-mapping>

<sql-query name="proc_drsrr_sel_ValDDSummaryBal">
<!--CALL proc_drsrr_sel_ValDDSummaryBal(:param1)]]>-->
{ call DEFAULT_SCHEMA.proc_name(?,:param1) }

主类:

public static void main(String[] args) {
String procName = "proc_name";// args[0];
String params = "param1:500089" ;

DAO 实现:

@SuppressWarnings("unchecked")
public void callProc(String procName, Map paramMap) throws SQLException {
Session session = null;
Transaction tx = null;
try {

session = HibernateUtils.getSessionFactory().getCurrentSession();
tx = session.beginTransaction();
String dbURL = session.connection().getMetaData().getURL().toString();
System.out.println("Conenction DB URL "+ dbURL );
tx.setTimeout(5);
String[] keys = new String[paramMap.size()];
keys = (String[]) paramMap.keySet().toArray(keys);

Query query = session.getNamedQuery(procName)
.setParameter("param1", "5501010");

}

List result = query.list();
System.out.println(query.getQueryString());
for (int i = 0; i < result.size(); i++) {
// logging the information.
log.info(i);

}
tx.commit();
} catch (RuntimeException exception) {
exception.printStackTrace();
try {
tx.rollback();
} catch (RuntimeException rbe) {
log.error("Couldn’t roll back transaction", rbe);
rbe.printStackTrace();
}
throw exception;
} finally{
if(session !=null){
session.flush();
session.close();
}

配置文件

<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.url">jdbc:oracle:thin:@ldap://hdsoid.ute.ovi.com:3060/UT1DEV,cn=OracleContext,dc=ute,dc=ovi,dc=com</property>
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.username">nameapp</property>
<property name="connection.password">nameapp</property>
<property name="connection.pool_size">1</property>
<property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>
<!-- <property name="connection.release_mode">after_statement</property> -->
<property name="default_schema">DEFAULT_SCHEMA</property>

<property name="current_session_context_class">thread</property>
<property name="hibernate.show_sql">true</property>
<!-- mapping files -->
<mapping resource="com/ovi/domain/hibernate.hbm.xml" />
</session-factory>
</hibernate-configuration>

最佳答案

您没有设置 ? 参数,这是一个所谓的 positional parameter。与 :foo

等命名参数相比

当你有一些SQL时,你还必须确保注释中没有任何问号!那就是我刚遇到的。注释中的 : 也是如此,尤其是当它们后面跟有一个空格时。

关于java - 预期位置参数计数 : 1, 实际参数:[],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14490111/

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