Kawai Wiki

Rev

Rev 49 | Blame | Compare with Previous | Last modification | View Log | RSS feed

package org.kawai.dao.jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import org.mentabean.BeanSession;

/**
 * Abstract DAO class AbstractJdbcDAO.
 *
 * @author Sergio Oliveira
 *
 */

public abstract class AbstractJdbcDAO {

    /** Attribute session of AbstractJdbcDAO. */
    protected BeanSession session;
    /** Attribute conn of AbstractJdbcDAO. */
    protected Connection conn;

    /**
     * Parametric constructor.
     * @param session BeanSession
     */

    public AbstractJdbcDAO(BeanSession session) {
        this.session = session;
        this.conn = session.getConnection();
    }

    /**
     * Close connection resources.
     * @param stmt PreparedStatement
     * @param rset ResultSet
     */

    public final static void close(PreparedStatement stmt, ResultSet rset) {

        if (rset != null) try { rset.close(); } catch(Exception e) { e.printStackTrace(); }
        if (stmt != null) try { stmt.close(); } catch(Exception e) { e.printStackTrace(); }
    }

    /**
     * Close prepatedStatement.
     * @param stmt PreparedStatement
     */

    public final static void close(PreparedStatement stmt) {
        close(stmt, null);
    }
}