简体   繁体   English

mysql存储过程调用手动工作,但不能从java

[英]mysql stored procedure call works manually, but not from java

I'm calling a mysql stored procedure from Java like this: 我正在从Java调用mysql存储过程,如下所示:

public void deleteMyProduct(final String country, final String someId) throws EntityDoesNotExistException {
        getHibernateTemplate().execute(new HibernateCallback() {

            public Object doInHibernate(final Session session) {
                session.clear();    
                Connection con = session.connection();
                try {
                    CallableStatement cst = con.prepareCall("{call deleteProduct( ?, ? )}");
                    cst.setString(1 , country);
                    cst.setString(2 , someId);
                    cst.execute();
                    cst.close();    
                }
                catch(SQLException e){
                    logger.error("Error deleting product, someId:  "+ someId, e);
                }
                return null;
            }
        });

It's not successfully deleting the product; 无法成功删除产品; however when I run it manually, it does. 但是,当我手动运行它时,它确实可以。 Any idea what the problem could be? 知道可能是什么问题吗?

ps the stored procedure is pretty large and contains identifiable info, so I'm not at liberty to post it. ps存储过程很大,并且包含可识别的信息,因此我没有随意发布它的权利。 However, it's been in production for a while and only recently just stopped working. 但是,它已经投入生产了一段时间,直到最近才停止工作。

  1. Are you sure the code is getting executed? 您确定代码正在执行吗?
  2. Are variables country and someId actually correct? 变量countrysomeId实际上正确吗?
  3. What does the SQLException say? SQLException说什么?
  4. Do get a successful connection - Connection con = session.connection(); 获得成功的连接Connection con = session.connection(); ?
  5. Are you passing the right types of variables(should you send Int instead of String )? 您是否传递了正确的变量类型(您应该发送Int而不是String )?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM