Sajmon

Example of RevisionDAO

May 8th, 2012
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.68 KB | None | 0 0
  1. /**
  2.  * @author Sajmon
  3.  */
  4.  
  5. package DTOs;
  6.  
  7. import OraclDAOFactory.OracleDAOFactory;
  8. import java.sql.Connection;
  9. import java.sql.PreparedStatement;
  10. import java.sql.ResultSet;
  11. import java.sql.SQLException;
  12. import java.util.ArrayList;
  13. import java.util.List;
  14. import java.util.logging.Level;
  15. import java.util.logging.Logger;
  16.  
  17. public class RevisionDAO {
  18.    
  19.     private final String SELECT_ALL = "SELECT * FROM Revision";
  20.    
  21.    
  22.     public RevisionDAO() {
  23.    
  24.     }
  25.    
  26.    
  27.     public List<RevisionDTO> getAll() {
  28.        
  29.         List<RevisionDTO> data = new ArrayList<RevisionDTO>();
  30.         RevisionDTO member;
  31.        
  32.         Connection con = null;
  33.         PreparedStatement ps = null;
  34.         ResultSet rs = null;
  35.        
  36.         try {
  37.             con = getOracleDatabaseConnection();
  38.             ps = con.prepareStatement(SELECT_ALL);
  39.             rs = ps.executeQuery();
  40.             while (rs.next()) {
  41.                 member = new RevisionDTO();
  42.                 member.setISBN(rs.getString(1));
  43.                 member.setYear(rs.getInt(2));
  44.                 member.setCover(rs.getInt(3));
  45.                 member.setPages(rs.getInt(4));
  46.                 member.setLanguage(rs.getString(5));
  47.                 member.setTranslator(rs.getString(6));
  48.                 member.setBook(new BookDTO());
  49.                 member.getBook().setId(rs.getInt(7));
  50.                 data.add(member);
  51.             }
  52.             System.out.println("Revision imported successfully.");
  53.             return data;
  54.         }
  55.         catch (SQLException ex) {
  56.             Logger.getLogger(RevisionDAO.class.getName()).log(Level.SEVERE, null, ex);
  57.             return null;
  58.         }
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment