-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: JDBC call from hibernate; Statement has already been closed.
PostPosted: Fri Nov 24, 2006 5:23 pm 
Newbie

Joined: Mon Nov 20, 2006 6:30 pm
Posts: 3
Hi guys!

I'm trying to use Hibernate in old JDBC way, but for some reason, when
calling executeQuery() an exception:

java.sql.SQLException: Statement has already been closed

Any idea about this?

Thanks,
Horatiu

Code:
HashMap<Long, String> typesHash = new HashMap<Long,String>();
       
        String sqlQuery = "SELECT " +
        "       pcf.field_sk, atc.data_type "+
        "FROM   " +
        "       package_criteria_fields pcf, all_tab_columns atc "+
        "WHERE  "+
        "         admin_type = "+adminType+
        "     AND  " +
        "         benefit_g20sk = "+benefitType+
        "     AND " +
        "         atc.table_name = pcf.table_name " +
        "     AND " +
        "         atc.column_name = pcf.column_name order by pcf.field_sk ";   
       
        Session session = this.getSession();
        try {
            Connection connection = session.connection();
            try {
                Statement statement = connection.createStatement();
                ResultSet rs = null;
                try {
                    rs = statement.executeQuery(sqlQuery);
                   
                    while(null != rs && rs.next()){
                        typesHash.put(new Long(rs.getInt(0)), rs.getString(1));
                    }
                }catch(Exception e){
                 logger.error("Cannot retrieve the types of criteria fields from the database.");
                 //@todo a system error should be thrown.
                 throw new RuntimeException("Cannot retrieve the types of criteria fields from the database.");
                }finally {                   
                    statement.close();
                    if(null != rs){
                        rs.close();
                    }
                }
            }
            catch (HibernateException e) {
                connection.rollback();
                logger.error("Cannot create a Statement object from Connection.");
                //@todo a system error should be thrown.
                throw new RuntimeException("Cannot create a Statement object from Connection.");
            }
            catch (SQLException e) {
                connection.rollback();
                logger.error("Cannot create a Statement object from Connection.");
                //@todo a system error should be thrown.
                throw new RuntimeException("Cannot create a Statement object from Connection.");
           
            }
        }
        catch (SQLException e) {
            logger.error("Cannot get a Connection from the Hibernate Session.");
            //@todo a system error should be thrown.
            throw new RuntimeException("Cannot get a Connection from the Hibernate Session.");
        }
        finally {
            session.close();
        }


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 27, 2006 3:58 am 
Senior
Senior

Joined: Sat Jul 17, 2004 5:16 pm
Posts: 143
post the whole stacktrace. I do the same thing and it works fine. Maybe something is wrong with the connection that Hibernate Session is using. Chris


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.