| 1 package org.mvnforum.phpbb2mvnforum.db.jdbc; 2 3 import java.sql.Connection ; 4 import java.sql.PreparedStatement ; 5 import java.sql.ResultSet ; 6 import java.sql.SQLException ; 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 21 public PhpbbPostText getBean(int post_id) throws ObjectNotFoundException, DatabaseException { 22 23 Connection connection = null; 24 PreparedStatement statement = null; 25 ResultSet resultSet = null; 26 StringBuffer sql = new StringBuffer (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 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 58 public String getPostTextFromPostID(int post_id) throws ObjectNotFoundException, DatabaseException { 59 60 Connection connection = null; 61 PreparedStatement statement = null; 62 ResultSet resultSet = null; 63 StringBuffer sql = new StringBuffer (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 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 |