KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mvnforum > phpbb2mvnforum > db > jdbc > PhpbbPostTextDAOImpl


1 package org.mvnforum.phpbb2mvnforum.db.jdbc;
2
3 import java.sql.Connection JavaDoc;
4 import java.sql.PreparedStatement JavaDoc;
5 import java.sql.ResultSet JavaDoc;
6 import java.sql.SQLException JavaDoc;
7
8 import net.myvietnam.mvncore.exception.DatabaseException;
9 import net.myvietnam.mvncore.exception.ObjectNotFoundException;
10
11 import org.mvnforum.phpbb2mvnforum.db.PhpbbPostText;
12 import org.mvnforum.phpbb2mvnforum.db.PhpbbPostTextDAO;
13 import org.mvnforum.util.DBUtils;
14
15 public class PhpbbPostTextDAOImpl implements PhpbbPostTextDAO {
16     
17     /*
18      * Included columns: post_id, bbcode_uid, post_subject, post_text
19      * Excluded columns:
20      */

21     public PhpbbPostText getBean(int post_id) throws ObjectNotFoundException, DatabaseException {
22
23         Connection JavaDoc connection = null;
24         PreparedStatement JavaDoc statement = null;
25         ResultSet JavaDoc resultSet = null;
26         StringBuffer JavaDoc sql = new StringBuffer JavaDoc(512);
27         sql.append("SELECT post_id, bbcode_uid, post_subject, post_text");
28         sql.append(" FROM " + TABLE_NAME);
29         sql.append(" WHERE post_id = ?");
30         try {
31             connection = DBUtils.getPhpbbConnection();
32             statement = connection.prepareStatement(sql.toString());
33             statement.setInt(1, post_id);
34             resultSet = statement.executeQuery();
35             if(!resultSet.next()) {
36                 throw new ObjectNotFoundException("Cannot find the row in table phpbb_posts_text where primary key = (" + post_id + ").");
37             }
38
39             PhpbbPostText bean = new PhpbbPostText();
40             bean.setpost_id(resultSet.getInt("post_id"));
41             bean.setbbcode_uid(resultSet.getString("bbcode_uid"));
42             bean.setpost_subject(resultSet.getString("post_subject"));
43             bean.setpost_text(resultSet.getString("post_text"));
44             return bean;
45         } catch(SQLException JavaDoc sqle) {
46             throw new DatabaseException("Error executing SQL in phpbb_posts_textDAOImplJDBC.getBean(pk).");
47         } finally {
48             DBUtils.closeResultSet(resultSet);
49             DBUtils.closeStatement(statement);
50             DBUtils.closeConnection(connection);
51         }
52     }
53     
54     /*
55      * Included columns: post_id, bbcode_uid, post_subject, post_text
56      * Excluded columns:
57      */

58     public String JavaDoc getPostTextFromPostID(int post_id) throws ObjectNotFoundException, DatabaseException {
59
60         Connection JavaDoc connection = null;
61         PreparedStatement JavaDoc statement = null;
62         ResultSet JavaDoc resultSet = null;
63         StringBuffer JavaDoc sql = new StringBuffer JavaDoc(512);
64         sql.append("SELECT post_text");
65         sql.append(" FROM " + TABLE_NAME);
66         sql.append(" WHERE post_id = ?");
67         try {
68             connection = DBUtils.getPhpbbConnection();
69             statement = connection.prepareStatement(sql.toString());
70             statement.setInt(1, post_id);
71             resultSet = statement.executeQuery();
72             if(!resultSet.next()) {
73                 throw new ObjectNotFoundException("Cannot find the row in table phpbb_posts_text where primary key = (" + post_id + ").");
74             }
75             return resultSet.getString("post_text");
76         } catch(SQLException JavaDoc sqle) {
77             throw new DatabaseException("Error executing SQL in phpbb_posts_textDAOImplJDBC.getBean(pk).");
78         } finally {
79             DBUtils.closeResultSet(resultSet);
80             DBUtils.closeStatement(statement);
81             DBUtils.closeConnection(connection);
82         }
83     }
84
85
86
87
88
89 }
90
Popular Tags