Rev 49 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 49 | Rev 195 | ||
---|---|---|---|
Line 4... | Line 4... | ||
4 | import java.sql.PreparedStatement; |
4 | import java.sql.PreparedStatement; |
5 | import java.sql.ResultSet; |
5 | import java.sql.ResultSet; |
6 | 6 | ||
7 | import org.mentabean.BeanSession; |
7 | import org.mentabean.BeanSession; |
8 | 8 | ||
- | 9 | /**
|
|
- | 10 | * Abstract DAO class AbstractJdbcDAO.
|
|
- | 11 | *
|
|
- | 12 | * @author Sergio Oliveira
|
|
- | 13 | *
|
|
- | 14 | */
|
|
9 | public abstract class AbstractJdbcDAO { |
15 | public abstract class AbstractJdbcDAO { |
10 | - | ||
11 | protected BeanSession session; |
- | |
12 | protected Connection conn; |
- | |
13 | - | ||
14 | public AbstractJdbcDAO(BeanSession session) { |
- | |
15 | this.session = session; |
- | |
16 | this.conn = session.getConnection(); |
- | |
17 | }
|
- | |
18 | - | ||
19 | public final static void close(PreparedStatement stmt, ResultSet rset) { |
- | |
20 | - | ||
21 | if (rset != null) try { rset.close(); } catch(Exception e) { e.printStackTrace(); } |
- | |
22 | if (stmt != null) try { stmt.close(); } catch(Exception e) { e.printStackTrace(); } |
- | |
23 | }
|
- | |
24 | - | ||
25 | public final static void close(PreparedStatement stmt) { |
- | |
26 | close(stmt, null); |
- | |
27 | }
|
- | |
28 | }
|
16 | |
- | 17 | /** Attribute session of AbstractJdbcDAO. */
|
|
- | 18 | protected BeanSession session; |
|
- | 19 | /** Attribute conn of AbstractJdbcDAO. */
|
|
- | 20 | protected Connection conn; |
|
- | 21 | ||
- | 22 | /**
|
|
- | 23 | * Parametric constructor.
|
|
- | 24 | * @param session BeanSession
|
|
- | 25 | */
|
|
- | 26 | public AbstractJdbcDAO(BeanSession session) { |
|
- | 27 | this.session = session; |
|
- | 28 | this.conn = session.getConnection(); |
|
- | 29 | }
|
|
- | 30 | ||
- | 31 | /**
|
|
- | 32 | * Close connection resources.
|
|
- | 33 | * @param stmt PreparedStatement
|
|
- | 34 | * @param rset ResultSet
|
|
- | 35 | */
|
|
- | 36 | public final static void close(PreparedStatement stmt, ResultSet rset) { |
|
- | 37 | ||
- | 38 | if (rset != null) try { rset.close(); } catch(Exception e) { e.printStackTrace(); } |
|
- | 39 | if (stmt != null) try { stmt.close(); } catch(Exception e) { e.printStackTrace(); } |
|
- | 40 | }
|
|
- | 41 | ||
- | 42 | /**
|
|
- | 43 | * Close prepatedStatement.
|
|
- | 44 | * @param stmt PreparedStatement
|
|
- | 45 | */
|
|
- | 46 | public final static void close(PreparedStatement stmt) { |
|
- | 47 | close(stmt, null); |
|
- | 48 | }
|
|
- | 49 | }
|