简体   繁体   中英

mysql stored procedure call works manually, but not from java

I'm calling a mysql stored procedure from Java like this:

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. 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?
  3. What does the SQLException say?
  4. Do get a successful connection - Connection con = session.connection(); ?
  5. Are you passing the right types of variables(should you send Int instead of String )?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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