0

I am calling below method and need to insert records to a table via a stored procedure.

In my local machine update works always. In the server update stop after inserting a

record. It does not print any exception.

My method

public void executeTableUpdate(String sql) throws Exception {
    StatelessSession session = null;
    try {
        session = getSessionFactory().openStatelessSession();
        session.beginTransaction();
        int result = session.createSQLQuery(sql).executeUpdate();
    } catch (Exception ex) {
        e.getMessage();
    } finally {
        if (session != null) {
            try {
                session.getTransaction().commit();
                session.close();                    
            } catch (Exception exception) {
             exception.getMessage();
            }
        }
    }
}

The passing SQL is

call SP_UPDATE_STATUS(NOW(),'value1',NOW(),'value1',1,'summary',)

user3558691
  • 117
  • 2
  • 12

1 Answers1

0

Of course you can't see any exception, because you simply ignore them:

e.getMessage();

That's not how you handle exceptions.

A quick fix is:

e.printStackTrace();
  1. A better solution is to use a logging framework (Logback or Lof4j)
  2. Opening a Session every time you call this method is not efficient at all
  3. Manually opening/closing transactions shouldn't be the case for code that's meant to deployed on a server (use Java EE, Spring, or write your own interceptor to handle this task)
Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
Vlad Mihalcea
  • 142,745
  • 71
  • 566
  • 911