草庐IT

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

coder 2024-03-28 原文

当我尝试使用来自 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/

有关java - 预期位置参数计数 : 1, 实际参数:[]的更多相关文章

  1. ruby-on-rails - 如何验证 update_all 是否实际在 Rails 中更新 - 2

    给定这段代码defcreate@upgrades=User.update_all(["role=?","upgraded"],:id=>params[:upgrade])redirect_toadmin_upgrades_path,:notice=>"Successfullyupgradeduser."end我如何在该操作中实际验证它们是否已保存或未重定向到适当的页面和消息? 最佳答案 在Rails3中,update_all不返回任何有意义的信息,除了已更新的记录数(这可能取决于您的DBMS是否返回该信息)。http://ar.ru

  2. ruby-on-rails - 如何在 ruby​​ 中使用两个参数异步运行 exe? - 2

    exe应该在我打开页面时运行。异步进程需要运行。有什么方法可以在ruby​​中使用两个参数异步运行exe吗?我已经尝试过ruby​​命令-system()、exec()但它正在等待过程完成。我需要用参数启动exe,无需等待进程完成是否有任何ruby​​gems会支持我的问题? 最佳答案 您可以使用Process.spawn和Process.wait2:pid=Process.spawn'your.exe','--option'#Later...pid,status=Process.wait2pid您的程序将作为解释器的子进程执行。除

  3. ruby - RSpec - 使用测试替身作为 block 参数 - 2

    我有一些Ruby代码,如下所示:Something.createdo|x|x.foo=barend我想编写一个测试,它使用double代替block参数x,这样我就可以调用:x_double.should_receive(:foo).with("whatever").这可能吗? 最佳答案 specify'something'dox=doublex.should_receive(:foo=).with("whatever")Something.should_receive(:create).and_yield(x)#callthere

  4. ruby - 如何在 Ruby 中拆分参数字符串 Bash 样式? - 2

    我正在为一个项目制作一个简单的shell,我希望像在Bash中一样解析参数字符串。foobar"helloworld"fooz应该变成:["foo","bar","helloworld","fooz"]等等。到目前为止,我一直在使用CSV::parse_line,将列分隔符设置为""和.compact输出。问题是我现在必须选择是要支持单引号还是双引号。CSV不支持超过一个分隔符。Python有一个名为shlex的模块:>>>shlex.split("Test'helloworld'foo")['Test','helloworld','foo']>>>shlex.split('Test"

  5. ruby - 检查方法参数的类型 - 2

    我不确定传递给方法的对象的类型是否正确。我可能会将一个字符串传递给一个只能处理整数的函数。某种运行时保证怎么样?我看不到比以下更好的选择:defsomeFixNumMangler(input)raise"wrongtype:integerrequired"unlessinput.class==FixNumother_stuffend有更好的选择吗? 最佳答案 使用Kernel#Integer在使用之前转换输入的方法。当无法以任何合理的方式将输入转换为整数时,它将引发ArgumentError。defmy_method(number)

  6. java - 等价于 Java 中的 Ruby Hash - 2

    我真的很习惯使用Ruby编写以下代码:my_hash={}my_hash['test']=1Java中对应的数据结构是什么? 最佳答案 HashMapmap=newHashMap();map.put("test",1);我假设? 关于java-等价于Java中的RubyHash,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/22737685/

  7. ruby-on-rails - 在默认方法参数中使用 .reverse_merge 或 .merge - 2

    两者都可以defsetup(options={})options.reverse_merge:size=>25,:velocity=>10end和defsetup(options={}){:size=>25,:velocity=>10}.merge(options)end在方法的参数中分配默认值。问题是:哪个更好?您更愿意使用哪一个?在性能、代码可读性或其他方面有什么不同吗?编辑:我无意中添加了bang(!)...并不是要询问nobang方法与bang方法之间的区别 最佳答案 我倾向于使用reverse_merge方法:option

  8. ruby - 定义方法参数的条件 - 2

    我有一个只接受一个参数的方法:defmy_method(number)end如果使用number调用方法,我该如何引发错误??通常,我如何定义方法参数的条件?比如我想在调用的时候报错:my_method(1) 最佳答案 您可以添加guard在函数的开头,如果参数无效则引发异常。例如:defmy_method(number)failArgumentError,"Inputshouldbegreaterthanorequalto2"ifnumbereputse.messageend#=>Inputshouldbegreaterthano

  9. ruby - rails 3 redirect_to 将参数传递给命名路由 - 2

    我没有找到太多关于如何执行此操作的信息,尽管有很多关于如何使用像这样的redirect_to将参数传递给重定向的建议:action=>'something',:controller=>'something'在我的应用程序中,我在路由文件中有以下内容match'profile'=>'User#show'我的表演Action是这样的defshow@user=User.find(params[:user])@title=@user.first_nameend重定向发生在同一个用户Controller中,就像这样defregister@title="Registration"@user=Use

  10. ruby-on-rails - Ruby on Rails 计数器缓存错误 - 2

    尝试在我的RoR应用程序中实现计数器缓存列时出现错误Unknownkey(s):counter_cache。我在这个问题中实现了模型关联:Modelassociationquestion这是我的迁移:classAddVideoVotesCountToVideos0Video.reset_column_informationVideo.find(:all).eachdo|p|p.update_attributes:videos_votes_count,p.video_votes.lengthendenddefself.downremove_column:videos,:video_vot

随机推荐