0

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?

p.s. 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 Answer 1

1
  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)?
Sign up to request clarification or add additional context in comments.

4 Comments

I would post this "answer" as a comment to the question, but it seems I need more reputation to do that..
How would I view SQLException? Yes variables are definitely correct. Also, I'm debugging the code through the execute of the stored procedure - but I can't walk into it.
What I meant with that was, if you get any exceptions thrown, but if you're debugging through it, I guess you would see if that would happen..
It turns out, the program was sending setting the variable the opposite of what they were in the stored procedure! When I ran the stored procedure manually I was setting them correctly, so I didn't notice that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.