org.hibernate.exception.SQLGrammarException:执行工作错误&

时间:2018-01-22 16:26:46

标签: java xml hibernate

这是我的MyWork课程

public class MyWork implements Work
 {
    @Override
    public void execute(Connection con) throws SQLException 
    {
        CallableStatement cstmt=con.prepareCall("{?=call emp_bonus(?)}");
        cstmt.registerOutParameter(1, Types.DOUBLE);
        Scanner s= new Scanner(System.in);
        System.out.println("enter employee number");
        int eno=s.nextInt();
        cstmt.setInt(2, eno);
        cstmt.execute();
        Double bonus=cstmt.getDouble(1);
        System.out.println("Bonus="+bonus);
        cstmt.close();
    }
}

这是我的测试类

package com.sathya.test;

import org.hibernate.Session;
import org.hibernate.SessionFactory;

import com.sathya.util.HibernateUtil;

public class Test {

    public static void main(String[] args) 
    {
        SessionFactory factory=HibernateUtil.getSessionFactory();
        Session session=factory.openSession();
        session.doWork(new MyWork());
        session.close();
    }

}

**

  

我收到错误

org.hibernate.exception.SQLGrammarException:执行错误

**

1 个答案:

答案 0 :(得分:1)

你能检查一下这是否正确:

 CallableStatement cstmt=con.prepareCall("{?=call emp_bonus(?)}");

传递的参数数量与数据库过程匹配。