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 import java.util.ArrayList ; 8 import java.util.Collection ; 9 10 import net.myvietnam.mvncore.exception.DatabaseException; 11 12 import org.mvnforum.phpbb2mvnforum.db.PhpbbCategories; 13 import org.mvnforum.phpbb2mvnforum.db.PhpbbCategoriesDAO; 14 import org.mvnforum.util.DBUtils; 15 16 public class PhpbbCategoriesDAOImpl implements PhpbbCategoriesDAO { 17 18 private static final String TABLE_NAME = "phpbb_categories"; 19 20 24 public Collection getBeans() 25 throws DatabaseException { 26 27 Connection connection = null; 28 PreparedStatement statement = null; 29 ResultSet resultSet = null; 30 Collection retValue = new ArrayList (); 31 StringBuffer sql = new StringBuffer (512); 32 sql.append("SELECT cat_id, cat_title, cat_order"); 33 sql.append(" FROM " + TABLE_NAME); 34 try { 37 connection = DBUtils.getPhpbbConnection(); 38 statement = connection.prepareStatement(sql.toString()); 39 resultSet = statement.executeQuery(); 40 while (resultSet.next()) { 41 PhpbbCategories bean = new PhpbbCategories(); 42 bean.setCatId(resultSet.getInt("cat_id")); 43 bean.setCatTitle(resultSet.getString("cat_title")); 44 bean.setCatOrder(resultSet.getInt("cat_order")); 45 retValue.add(bean); 46 } 47 return retValue; 48 } catch(SQLException sqle) { 49 throw new DatabaseException("Error executing SQL in phpbb_categoriesDAOImplJDBC.getBeans."); 50 } finally { 51 DBUtils.closeResultSet(resultSet); 52 DBUtils.closeStatement(statement); 53 DBUtils.closeConnection(connection); 54 } 55 } 56 57 58 59 60 } 61 | Popular Tags |