Advertisement
Guest User

missing documents

a guest
Feb 15th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.14 KB | None | 0 0
  1. package application;
  2.  
  3. import java.io.File;
  4. import java.sql.Connection;
  5. import java.sql.DriverManager;
  6. import java.sql.PreparedStatement;
  7. import java.sql.ResultSet;
  8. import java.sql.SQLException;
  9.  
  10. import javafx.stage.Stage;
  11.  
  12. public class MissingDocuments extends Stage {
  13.     public MissingDocuments(Stage prev) {
  14.         // TODO Auto-generated constructor stub.
  15.         Stage current = this;
  16.         try {
  17.             setAttributes(current);
  18.         } catch (SQLException e) {
  19.             // TODO Auto-generated catch block
  20.             e.printStackTrace();
  21.         }
  22.     }
  23.     private void setAttributes(Stage current) throws SQLException {
  24.         Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/company?useSSL=false","root", "admin");
  25.         String select ="select distinct patientID,serviceID,providerID from patientServiceProvider ";
  26.         PreparedStatement searchStmt = conn.prepareStatement(select);
  27.         ResultSet result=searchStmt.executeQuery();
  28.        
  29.         while(  result.next()) {
  30.             int ID=result.getInt("patientID");
  31.             int numberOfFoundedReports=0;
  32.  
  33.             String CoID=getName("patient", "ID", "CoID", ID);
  34.            
  35.             System.out.println(CoID);
  36.             String path ="D:\\رؤية\\"+CoID+"\\document";
  37.             File providerFile= new File(path);
  38.             if(providerFile.exists()) {
  39.                 numberOfFoundedReports=countNumberOfFiles(path);
  40.             }
  41.  
  42.             if(numberOfFoundedReports==0) {
  43.                 System.out.println("patient with CoID =  "+CoID +"  has No documents" );
  44.  
  45.             }
  46.            
  47.         }  
  48.  
  49.     }
  50.     private String getName(String table,String conditon,String nameColumn,int id) throws SQLException {
  51.         String name=null;
  52.          Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/company?useSSL=false","root", "admin");
  53.  
  54.         String search="select * from "+table+" where "+conditon+" = ?";                
  55.         PreparedStatement searchStmt = conn.prepareStatement(search);
  56.         searchStmt.setInt(1, id);
  57.         ResultSet result=searchStmt.executeQuery();
  58.        
  59.         while(  result.next()) {
  60.             name=result.getString(nameColumn);
  61.  
  62.         }  
  63.         conn.close();
  64.         return name;
  65.  
  66.  
  67.     }
  68.     private int countNumberOfFiles(String dirPath) {
  69.         return new File(dirPath).listFiles().length;
  70. }
  71.  
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement