Ejemplo n.º 1
0
 @Override
 public int countImagesByPage(PageText page) {
   String sql = "SELECT COUNT(id) FROM imagespages WHERE idpagetext=" + page.getId();
   Statement stat = null;
   int count = 0;
   try {
     conn = myDataSource.getConnection();
     stat = conn.createStatement();
     ResultSet rs = stat.executeQuery(sql);
     if (rs.next()) {
       count = rs.getInt(1);
     }
   } catch (SQLException ex) {
     Logger.getLogger(MessagesServiceDaoImpl.class.getName()).log(Level.SEVERE, null, ex);
   } finally {
     try {
       if (stat != null) {
         stat.close();
       }
       myDataSource.closeConnection();
     } catch (SQLException ex) {
       Logger.getLogger(MessagesServiceDaoImpl.class.getName()).log(Level.SEVERE, null, ex);
     }
   }
   return count;
 }
Ejemplo n.º 2
0
 @Override
 public List<ImagesPage> findImagesByPageWithoutData(PageText page) {
   List<ImagesPage> imagesList = new ArrayList<>();
   ImagesPage image = null;
   String sql = "SELECT * FROM imagespages WHERE idpagetext=" + page.getId();
   try {
     conn = myDataSource.getConnection();
     Statement stat = conn.createStatement();
     ResultSet rs = stat.executeQuery(sql);
     while (rs.next()) {
       image = new ImagesPage();
       image.setId(rs.getInt(1));
       image.setDirectory(rs.getString(5));
       image.setFilename(rs.getString(4));
       image.setIdPageText(rs.getInt(3));
       imagesList.add(image);
     }
   } catch (SQLException ex) {
     LOG.log(Level.SEVERE, null, ex);
   } finally {
     try {
       conn.close();
     } catch (SQLException ex) {
       LOG.log(Level.SEVERE, null, ex);
     }
   }
   return imagesList;
 }