1 2 Previous Next 18 Replies Latest reply: Jul 16, 2008 12:10 PM by 843785 RSS

    search patient by patient id , first name , last name , date of birth

    800625
      hi all...

      i am trying to search patient by patient id , first name , last name , date of birth...
      i m trying.. and try to write this code but i m not going the write way.... so any body help....

      i m just putting the method here...



      public PatientData[] searchPatient(PatientData obj) {

                int patientid = obj.getPatientId();
                String firstname = obj.getPatientFirstName();
                String lastname = obj.getPatientLastName();
                String dateofbirth = obj.getPatientDateOfBirth();

                String url = "jdbc:mysql://localhost/mokshadatabase";
                String user = "root";
                String password = "password";
                String jdbcDriver = "com.mysql.jdbc.Driver";

                PatientData list[] = null;
                int i = 0;

                String query = null;

      try {
                     Class.forName(jdbcDriver).newInstance();
                     Connection cn = DriverManager.getConnection(url, user, password);

                     //---------- PATIENT ID -------- PATIENT ID ----------- PATIENT ID ---------------------
                     
                
                if (patientid != 0) {
                          
                try{
                          
                          if( (patientid != 0) && (firstname.equalsIgnoreCase(null)) && (lastname.equalsIgnoreCase(null)) && (dateofbirth.equalsIgnoreCase(null)) ){
                          
                               query = "select * from mhis_m_patientmaster where patient_Id like '%"+ patientid + "%' ";
                               
                     }
                } catch (NullPointerException e) {
                          System.out.println("error is : " + e.getMessage());
                          query = "select * from mhis_m_patientmaster where patient_Id like '%"+ patientid + "%' ";
                          
                }
                
                     
                try{
                          
                     if( (patientid != 0) && (!firstname.equalsIgnoreCase(null)) && (!lastname.equalsIgnoreCase(null)) && (!dateofbirth.equalsIgnoreCase(null)) ){
                          
                          query = "select * from mhis_m_patientmaster where patient_Id like '%"+ patientid+ "%' and patient_First_Name like '%"+ firstname+ "%' and patient_Last_Name like '%"+ lastname+ "%' and patient_Date_Of_Birth like '%" + dateofbirth + "%' ";

                }
                          
                } catch (NullPointerException e) {
                          System.out.println("error is : " + e.getMessage());
                          
                }     
                          
                
                try{
                          
                     if( (patientid != 0) && (!firstname.equalsIgnoreCase(null)) && (lastname.equalsIgnoreCase(null)) && (dateofbirth.equalsIgnoreCase(null)) ){
                          
                          query = "select * from mhis_m_patientmaster where patient_Id like '%"+ patientid+ "%' and patient_First_Name like '%"+ firstname+ "%' ";
                          
                     }

                } catch (NullPointerException e) {
                          System.out.println("error is : " + e.getMessage());
                          query = "select * from mhis_m_patientmaster where patient_Id like '%"+ patientid+ "%' and patient_First_Name like '%"+ firstname+ "%' ";
                          
                }
                     
                
                try{     
                          
                     if( (patientid != 0) && (!lastname.equalsIgnoreCase(null)) && (firstname.equalsIgnoreCase(null)) ){
                          
                          query = "select * from mhis_m_patientmaster where patient_Id like '%"+ patientid+ "%' and patient_Last_Name like '%"+ lastname+ "%' ";
                          
                     }
                } catch (NullPointerException e) {
                          System.out.println("error is : " + e.getMessage());
                          query = "select * from mhis_m_patientmaster where patient_Id like '%"+ patientid+ "%' and patient_Last_Name like '%"+ lastname+ "%' ";
                          
                }
                     
                
                try{
                
                          if( (patientid != 0) && (!dateofbirth.equalsIgnoreCase(null)) && (firstname.equalsIgnoreCase(null)) ){
                          
                          query = "select * from mhis_m_patientmaster where patient_Id like '%"+ patientid+ "%' and patient_Date_Of_Birth like '%"+ dateofbirth+ "%' ";
                     
                     }
                } catch (NullPointerException e) {
                          System.out.println("error is : " + e.getMessage());
                          query = "select * from mhis_m_patientmaster where patient_Id like '%"+ patientid+ "%' and patient_Date_Of_Birth like '%"+ dateofbirth+ "%' ";
                
                }
                
                     
                try{
                          
                     if( (patientid != 0) && (!firstname.equalsIgnoreCase(null)) && (!lastname.equalsIgnoreCase(null)) && (dateofbirth.equalsIgnoreCase(null)) ){
                          
                          query = "select * from mhis_m_patientmaster where patient_Id like '%"+ patientid+ "%' and patient_First_Name like '%"+ firstname+ "%' and patient_Last_Name like '%" + lastname + "%' ";
                          
                     }
                } catch (NullPointerException e) {
                          System.out.println("error is : " + e.getMessage());
                          
                }
                          
                          
                     
                try{
                
                if( (patientid != 0) && (!firstname.equalsIgnoreCase(null)) && (!dateofbirth.equalsIgnoreCase(null)) && (lastname.equalsIgnoreCase(null)) ){
                          
                          query = "select * from mhis_m_patientmaster where patient_Id like '%"+ patientid+ "%' and patient_First_Name like '%"+ firstname+ "%' and patient_Date_Of_Birth like '%" + dateofbirth + "%' ";

                     }
                } catch (NullPointerException e) {
                          System.out.println("error is : " + e.getMessage());
                          
                }
                          
                     
                try{
                
                          if( (patientid != 0) && (!lastname.equalsIgnoreCase(null)) && (!dateofbirth.equalsIgnoreCase(null)) && (firstname.equalsIgnoreCase(null)) ){
                          
                          query = "select * from mhis_m_patientmaster where patient_Id like '%"+ patientid+ "%' and patient_Last_Name like '%"+ lastname+ "%' and patient_Date_Of_Birth like '%" + dateofbirth + "%' ";
                          
                     }
                
                } catch(NullPointerException e) {
                          System.out.println("error is : " + e.getMessage());
                          
                }
                
                } // IF CLOSE
                
                
                //--------- FIRST NAME --------- FIRST NAME ----------- FIRST NAME ------------------------
                
                
                
                try{ 
                
                     if(!firstname.equalsIgnoreCase(null) && (patientid == 0) ){
                     
                     
                          try{
                
                               if(!firstname.equalsIgnoreCase(null) && (lastname.equalsIgnoreCase(null)) && (patientid == 0) ){
                     
                     query = "select * from mhis_m_patientmaster where patient_First_Name like '%"+ firstname + "%' ";

                          }
                          } catch (NullPointerException e) {
                                    System.out.println("error is : " + e.getMessage());
                                    query = "select * from mhis_m_patientmaster where patient_First_Name like '%"+ firstname + "%' ";

                          }
                
                
                try{
                
                     if( (!firstname.equalsIgnoreCase(null)) && (!lastname.equalsIgnoreCase(null)) && (patientid == 0) ){
                          
                               query = "select * from mhis_m_patientmaster where patient_First_Name like '%"+ firstname+ "%' and patient_Last_Name like '%"+ lastname+ "%' ";
                               
                          }
                } catch (NullPointerException e) {
                               System.out.println("error is : " + e.getMessage());
                               
                     }
                
                
                try{
                
                     if((!firstname.equalsIgnoreCase(null)) && (!dateofbirth.equalsIgnoreCase(null)) && (patientid == 0) ){
                               
                               query = "select * from mhis_m_patientmaster where patient_First_Name like '%"+ firstname+ "%' and patient_Date_Of_Birth like '%"+ dateofbirth+ "%' ";
                               
                          }
                } catch (NullPointerException e) {
                               System.out.println("error is : " + e.getMessage());
                               
                     }
                
                
                try{
                
                     if( (!firstname.equalsIgnoreCase(null)) && (!lastname.equalsIgnoreCase(null)) && (!dateofbirth.equalsIgnoreCase(null)) && (patientid == 0) ){
                
                               query = "select * from mhis_m_patientmaster where patient_First_Name like '%"+ firstname+ "%' and patient_Last_Name like '%"+ lastname+ "%' and patient_Date_Of_Birth like '%" + dateofbirth + "%' ";
           
                          }
                } catch (NullPointerException e) {
                               System.out.println("error is : " + e.getMessage());
                               
                     }
                
                
                     } // IF CLOSE
                
                } catch (NullPointerException e) {
                          System.out.println("error is : " + e.getMessage());
                          
                }
                
                
                
                //--------- LAST NAME -------- LAST NAME ----------- LAST NAME -------------------
                
                
           try{
                
                if( !lastname.equalsIgnoreCase(null) && (patientid == 0) ){
                
           
                     try{
                     
                          if( !lastname.equalsIgnoreCase(null) && (firstname.equalsIgnoreCase(null)) ){
                     
                     query = "select * from mhis_m_patientmaster where patient_Last_Name like '%"+ lastname + "%' ";
                     
                }
                     } catch (NullPointerException e) {
                               System.out.println("error is : " + e.getMessage());
                               query = "select * from mhis_m_patientmaster where patient_Last_Name like '%"+ lastname + "%' ";
                               
                     }
                
                
                     try{
                     
                          if( (!lastname.equalsIgnoreCase(null)) && (!dateofbirth.equalsIgnoreCase(null)) && (patientid == 0) ){
                     
                     query = "select * from mhis_m_patientmaster where patient_Last_Name like '%"+ lastname + "%' and patient_Date_Of_Birth like '%" + dateofbirth + "%' ";
                     
                }
                     } catch (NullPointerException e) {
                               System.out.println("error is : " + e.getMessage());
                               
                     }
                          
           } // IF CLOSE
                
           } catch (NullPointerException e) {
                     System.out.println("error is : " + e.getMessage());
                     
           }
                
           
                
           //-------- DATE OF BIRTH ------ DATE OF BIRTH --------- DATE OF BIRTH --------------------
                
                
           try{
                     
           if( (!dateofbirth.equalsIgnoreCase(null)) && (patientid == 0)){
                
                try{
                
                     if(!dateofbirth.equalsIgnoreCase(null)){

                     query = "select * from mhis_m_patientmaster where patient_Date_Of_Birth like '%"+ dateofbirth + "%' ";
                     
                     }
                
                }catch (NullPointerException e) {
                          System.out.println("error is : " + e.getMessage());
                          
                }
                     
                     
                try{
                     
                          if( !dateofbirth.equalsIgnoreCase(null) && (firstname.equalsIgnoreCase(null)) && (patientid == 0) ){
                     
                          query = "select * from mhis_m_patientmaster where patient_Date_Of_Birth like '%"+ dateofbirth + "%' ";
                     
                }
                          
                }catch (NullPointerException e) {
                               System.out.println("error is : " + e.getMessage());
                               
                     }
                          
           }     
                          
           } catch (NullPointerException e) {
                     System.out.println("error is : " + e.getMessage());
                     
           }

                
                
      PreparedStatement stmt = cn.prepareStatement(query);

                     stmt.executeQuery();

                     ResultSet rs = stmt.getResultSet();

                     for (i = 0; rs.next(); i++) {
                          System.out.println("Check");
                     }
                     list = new PatientData;
                     rs.beforeFirst();

                     for (i = 0; rs.next(); i++) {

                          list[i] = new PatientData();

                          list[i].setPatientId(rs.getInt("patient_Id"));
                          list[i].setPatientRegistrationDate(rs.getString("patient_Registration_Date"));
                          list[i].setPatientRegistrationTime(rs.getString("patient_Registration_Time"));
                          list[i].setPatientFirstName(rs.getString("patient_First_Name"));
                          list[i].setPatientLastName(rs.getString("patient_Last_Name"));
                          list[i].setPatientDateOfBirth(rs.getString("patient_Date_Of_Birth"));
                          list[i].setPatientAge(rs.getString("patient_Age"));
                          list[i].setPatientGender(rs.getString("patient_Gender"));
                          list[i].setPatientBloodGroup(rs.getString("patient_Blood_Group"));
                          list[i].setPatientHeight(rs.getFloat("patient_Height"));
                          list[i].setPatientPhoneNo(rs.getString("patient_Phone_No"));
                          list[i].setPatientAddress(rs.getString("patient_Address"));
                          list[i].setPatientZip(rs.getString("patient_Zip"));
                          list[i].setPatientMartialStatus(rs.getString("patient_Martial_Status"));
                          list[i].setPatientHusbandName(rs.getString("patient_Husband_Name"));
                          list[i].setPatientFatherName(rs.getString("patient_Father_Name"));
                          list[i].setPatientInsuranceCompany(rs.getString("patient_Insurance_Company"));
                          list[i].setPatientInsuranceNumber(rs.getString("patient_Insurance_Number"));
                          list[i].setPatientReligion(rs.getString("patient_Religion"));
                          list[i].setPatientCategory(rs.getString("patient_Category"));
                          list[i].setPatientCreatedBy(rs.getString("patient_Created_By"));
                          list[i].setPatientModifiedBy(rs.getString("patient_Modified_By"));
                          
                     }

                     stmt.close();
                     cn.close();

                } catch (IllegalAccessException e) {
                     return null;
                } catch (SQLException e) {
                     System.out.println("error is : " + e.getMessage());
                     return null;
                } catch (ClassNotFoundException e) {
                     return null;
                } catch (InstantiationException e) {
                     return null;
                } catch (NullPointerException e) {
                     System.out.println("error is : " + e.getMessage());
                     return null;
                }

                return list;

           }
        • 1. Re: search patient by patient id , first name , last name , date of birth
          800308
          Dude, post your code again... formatted properly. I'm not even going to look at that mess, incase it impregnates my cat.

          THE UBIQUITIOUS SUN FORUM POSTING TIPS

          * To make your code easier to read post it between code tags:
            - That is: {code} ... your code goes here ... {code}
            - the code tags preserve whitespace and hightlight java syntax.
            - copy & paste your code into the forum editor "as is". Editing code in the forum editor is a BAD idea.
            - The forums tabwidth is 8, as per [the java coding conventions|http://java.sun.com/docs/codeconv/].
            - Using an IDE with no respect for whitespace? Delete it. Now!

          * Post any error messages complete! between code tags:
            - {code} ... your errors go here ... {code}
            - error messages may be rendered useless if the code has been modified AT ALL since the error message was produced.

          * If you want good answers then read about [How to ask good questions|http://www.catb.org/~esr/faqs/smart-questions.html].

          * Improve your chances of getting laid tonight by writing an SSCCE.

          Cheers. Keith.

          Edited by: corlettk on 16/07/2008 13:52 - I still HATE this new forum editor!
          • 2. Re: search patient by patient id , first name , last name , date of birth
            843785
            1. NEVER! I repeat NEVER catch a NullPointerException. If you do not under stand this look at http://forum.java.sun.com/thread.jspa?threadID=5314187&tstart=0.

            2. Please place your code in code blocks!
            • 3. Re: search patient by patient id , first name , last name , date of birth
              843785
              Post jdbc related questions here

              use code tags
              firstname.equalsIgnoreCase(null)
              The way you check null is not correct

              Try to build the query dynamically.
              StringBuilder sb = new StringBuilder( "select * from mhis_m_patientmaster " );
              Based on the fields, build your where clause.
              • 4. Re: search patient by patient id , first name , last name , date of birth
                800625
                hi all...

                i am trying to search patient by patient id , first name , last name , date of birth...
                i m trying.. and try to write this code but i m not going the write way.... so any body help....

                i m just putting the method here...


                public PatientData[] searchPatient(PatientData obj) {
                
                int patientid = obj.getPatientId();
                String firstname = obj.getPatientFirstName();
                String lastname = obj.getPatientLastName();
                String dateofbirth = obj.getPatientDateOfBirth();
                
                String url = "jdbc:mysql://localhost/mokshadatabase";
                String user = "root";
                String password = "password";
                String jdbcDriver = "com.mysql.jdbc.Driver";
                
                PatientData list[] = null;
                int i = 0;
                
                String query = null;
                
                try {
                Class.forName(jdbcDriver).newInstance();
                Connection cn = DriverManager.getConnection(url, user, password);
                
                //---------- PATIENT ID
                PATIENT ID PATIENT ID
                
                if (patientid != 0) {
                
                try{
                
                if( (patientid != 0) && (firstname.equalsIgnoreCase(null)) && (lastname.equalsIgnoreCase(null)) && (dateofbirth.equalsIgnoreCase(null)) ){
                
                query = "select * from mhis_m_patientmaster where patient_Id like '%"+ patientid + "%' ";
                
                }
                } catch (NullPointerException e) {
                System.out.println("error is : " + e.getMessage());
                query = "select * from mhis_m_patientmaster where patient_Id like '%"+ patientid + "%' ";
                
                }
                
                try{
                
                if( (patientid != 0) && (!firstname.equalsIgnoreCase(null)) && (!lastname.equalsIgnoreCase(null)) && (!dateofbirth.equalsIgnoreCase(null)) ){
                
                query = "select * from mhis_m_patientmaster where patient_Id like '%"+ patientid+ "%' and patient_First_Name like '%"+ firstname+ "%' and patient_Last_Name like '%"+ lastname+ "%' and patient_Date_Of_Birth like '%" + dateofbirth + "%' ";
                
                }
                
                } catch (NullPointerException e) {
                System.out.println("error is : " + e.getMessage());
                
                }
                
                try{
                
                if( (patientid != 0) && (!firstname.equalsIgnoreCase(null)) && (lastname.equalsIgnoreCase(null)) && (dateofbirth.equalsIgnoreCase(null)) ){
                
                query = "select * from mhis_m_patientmaster where patient_Id like '%"+ patientid+ "%' and patient_First_Name like '%"+ firstname+ "%' ";
                
                }
                
                } catch (NullPointerException e) {
                System.out.println("error is : " + e.getMessage());
                query = "select * from mhis_m_patientmaster where patient_Id like '%"+ patientid+ "%' and patient_First_Name like '%"+ firstname+ "%' ";
                
                }
                
                try{
                
                if( (patientid != 0) && (!lastname.equalsIgnoreCase(null)) && (firstname.equalsIgnoreCase(null)) ){
                
                query = "select * from mhis_m_patientmaster where patient_Id like '%"+ patientid+ "%' and patient_Last_Name like '%"+ lastname+ "%' ";
                
                }
                } catch (NullPointerException e) {
                System.out.println("error is : " + e.getMessage());
                query = "select * from mhis_m_patientmaster where patient_Id like '%"+ patientid+ "%' and patient_Last_Name like '%"+ lastname+ "%' ";
                
                }
                
                try{
                
                if( (patientid != 0) && (!dateofbirth.equalsIgnoreCase(null)) && (firstname.equalsIgnoreCase(null)) ){
                
                query = "select * from mhis_m_patientmaster where patient_Id like '%"+ patientid+ "%' and patient_Date_Of_Birth like '%"+ dateofbirth+ "%' ";
                
                }
                } catch (NullPointerException e) {
                System.out.println("error is : " + e.getMessage());
                query = "select * from mhis_m_patientmaster where patient_Id like '%"+ patientid+ "%' and patient_Date_Of_Birth like '%"+ dateofbirth+ "%' ";
                
                }
                
                try{
                
                if( (patientid != 0) && (!firstname.equalsIgnoreCase(null)) && (!lastname.equalsIgnoreCase(null)) && (dateofbirth.equalsIgnoreCase(null)) ){
                
                query = "select * from mhis_m_patientmaster where patient_Id like '%"+ patientid+ "%' and patient_First_Name like '%"+ firstname+ "%' and patient_Last_Name like '%" + lastname + "%' ";
                
                }
                } catch (NullPointerException e) {
                System.out.println("error is : " + e.getMessage());
                
                }
                
                
                try{
                
                if( (patientid != 0) && (!firstname.equalsIgnoreCase(null)) && (!dateofbirth.equalsIgnoreCase(null)) && (lastname.equalsIgnoreCase(null)) ){
                
                query = "select * from mhis_m_patientmaster where patient_Id like '%"+ patientid+ "%' and patient_First_Name like '%"+ firstname+ "%' and patient_Date_Of_Birth like '%" + dateofbirth + "%' ";
                
                }
                } catch (NullPointerException e) {
                System.out.println("error is : " + e.getMessage());
                
                }
                
                try{
                
                if( (patientid != 0) && (!lastname.equalsIgnoreCase(null)) && (!dateofbirth.equalsIgnoreCase(null)) && (firstname.equalsIgnoreCase(null)) ){
                
                query = "select * from mhis_m_patientmaster where patient_Id like '%"+ patientid+ "%' and patient_Last_Name like '%"+ lastname+ "%' and patient_Date_Of_Birth like '%" + dateofbirth + "%' ";
                
                }
                
                } catch(NullPointerException e) {
                System.out.println("error is : " + e.getMessage());
                
                }
                
                } // IF CLOSE
                
                //--------- FIRST NAME
                FIRST NAME FIRST NAME
                
                
                try{
                
                if(!firstname.equalsIgnoreCase(null) && (patientid == 0) ){
                
                try{
                
                if(!firstname.equalsIgnoreCase(null) && (lastname.equalsIgnoreCase(null)) && (patientid == 0) ){
                
                query = "select * from mhis_m_patientmaster where patient_First_Name like '%"+ firstname + "%' ";
                
                }
                } catch (NullPointerException e) {
                System.out.println("error is : " + e.getMessage());
                query = "select * from mhis_m_patientmaster where patient_First_Name like '%"+ firstname + "%' ";
                
                }
                
                try{
                
                if( (!firstname.equalsIgnoreCase(null)) && (!lastname.equalsIgnoreCase(null)) && (patientid == 0) ){
                
                query = "select * from mhis_m_patientmaster where patient_First_Name like '%"+ firstname+ "%' and patient_Last_Name like '%"+ lastname+ "%' ";
                
                }
                } catch (NullPointerException e) {
                System.out.println("error is : " + e.getMessage());
                
                }
                
                try{
                
                if((!firstname.equalsIgnoreCase(null)) && (!dateofbirth.equalsIgnoreCase(null)) && (patientid == 0) ){
                
                query = "select * from mhis_m_patientmaster where patient_First_Name like '%"+ firstname+ "%' and patient_Date_Of_Birth like '%"+ dateofbirth+ "%' ";
                
                }
                } catch (NullPointerException e) {
                System.out.println("error is : " + e.getMessage());
                
                }
                
                try{
                
                if( (!firstname.equalsIgnoreCase(null)) && (!lastname.equalsIgnoreCase(null)) && (!dateofbirth.equalsIgnoreCase(null)) && (patientid == 0) ){
                
                query = "select * from mhis_m_patientmaster where patient_First_Name like '%"+ firstname+ "%' and patient_Last_Name like '%"+ lastname+ "%' and patient_Date_Of_Birth like '%" + dateofbirth + "%' ";
                
                }
                } catch (NullPointerException e) {
                System.out.println("error is : " + e.getMessage());
                
                }
                
                } // IF CLOSE
                
                } catch (NullPointerException e) {
                System.out.println("error is : " + e.getMessage());
                
                }
                
                
                //--------- LAST NAME
                LAST NAME LAST NAME
                
                try{
                
                if( !lastname.equalsIgnoreCase(null) && (patientid == 0) ){
                
                try{
                
                if( !lastname.equalsIgnoreCase(null) && (firstname.equalsIgnoreCase(null)) ){
                
                query = "select * from mhis_m_patientmaster where patient_Last_Name like '%"+ lastname + "%' ";
                
                }
                } catch (NullPointerException e) {
                System.out.println("error is : " + e.getMessage());
                query = "select * from mhis_m_patientmaster where patient_Last_Name like '%"+ lastname + "%' ";
                
                }
                
                try{
                
                if( (!lastname.equalsIgnoreCase(null)) && (!dateofbirth.equalsIgnoreCase(null)) && (patientid == 0) ){
                
                query = "select * from mhis_m_patientmaster where patient_Last_Name like '%"+ lastname + "%' and patient_Date_Of_Birth like '%" + dateofbirth + "%' ";
                
                }
                } catch (NullPointerException e) {
                System.out.println("error is : " + e.getMessage());
                
                }
                
                } // IF CLOSE
                
                } catch (NullPointerException e) {
                System.out.println("error is : " + e.getMessage());
                
                }
                
                
                //-------- DATE OF BIRTH
                DATE OF BIRTH DATE OF BIRTH
                
                try{
                
                if( (!dateofbirth.equalsIgnoreCase(null)) && (patientid == 0)){
                
                try{
                
                if(!dateofbirth.equalsIgnoreCase(null)){
                
                query = "select * from mhis_m_patientmaster where patient_Date_Of_Birth like '%"+ dateofbirth + "%' ";
                
                }
                
                }catch (NullPointerException e) {
                System.out.println("error is : " + e.getMessage());
                
                }
                
                try{
                
                if( !dateofbirth.equalsIgnoreCase(null) && (firstname.equalsIgnoreCase(null)) && (patientid == 0) ){
                
                query = "select * from mhis_m_patientmaster where patient_Date_Of_Birth like '%"+ dateofbirth + "%' ";
                
                }
                
                }catch (NullPointerException e) {
                System.out.println("error is : " + e.getMessage());
                
                }
                
                }
                
                } catch (NullPointerException e) {
                System.out.println("error is : " + e.getMessage());
                
                }
                
                
                PreparedStatement stmt = cn.prepareStatement(query);
                
                stmt.executeQuery();
                
                ResultSet rs = stmt.getResultSet();
                
                for (i = 0; rs.next(); i++) {
                System.out.println("Check");
                }
                list = new PatientData;
                rs.beforeFirst();

                for (i = 0; rs.next(); i++) {

                list[i] = new PatientData();

                list[i].setPatientId(rs.getInt("patient_Id"));
                list[i].setPatientRegistrationDate(rs.getString("patient_Registration_Date"));
                list[i].setPatientRegistrationTime(rs.getString("patient_Registration_Time"));
                list[i].setPatientFirstName(rs.getString("patient_First_Name"));
                list[i].setPatientLastName(rs.getString("patient_Last_Name"));
                list[i].setPatientDateOfBirth(rs.getString("patient_Date_Of_Birth"));
                list[i].setPatientAge(rs.getString("patient_Age"));
                list[i].setPatientGender(rs.getString("patient_Gender"));
                list[i].setPatientBloodGroup(rs.getString("patient_Blood_Group"));
                list[i].setPatientHeight(rs.getFloat("patient_Height"));
                list[i].setPatientPhoneNo(rs.getString("patient_Phone_No"));
                list[i].setPatientAddress(rs.getString("patient_Address"));
                list[i].setPatientZip(rs.getString("patient_Zip"));
                list[i].setPatientMartialStatus(rs.getString("patient_Martial_Status"));
                list[i].setPatientHusbandName(rs.getString("patient_Husband_Name"));
                list[i].setPatientFatherName(rs.getString("patient_Father_Name"));
                list[i].setPatientInsuranceCompany(rs.getString("patient_Insurance_Company"));
                list[i].setPatientInsuranceNumber(rs.getString("patient_Insurance_Number"));
                list[i].setPatientReligion(rs.getString("patient_Religion"));
                list[i].setPatientCategory(rs.getString("patient_Category"));
                list[i].setPatientCreatedBy(rs.getString("patient_Created_By"));
                list[i].setPatientModifiedBy(rs.getString("patient_Modified_By"));

                }

                stmt.close();
                cn.close();

                } catch (IllegalAccessException e) {
                return null;
                } catch (SQLException e) {
                System.out.println("error is : " + e.getMessage());
                return null;
                } catch (ClassNotFoundException e) {
                return null;
                } catch (InstantiationException e) {
                return null;
                } catch (NullPointerException e) {
                System.out.println("error is : " + e.getMessage());
                return null;
                }

                return list;

                }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
                • 5. Re: search patient by patient id , first name , last name , date of birth
                  796254
                  this code absolutely, positively sucks. there's no other way to say it.

                  this ought to be several methods, written properly. I'd envision something like this:
                  public interface PatientDao
                  {
                      Patient find(Long id);
                      List<Patient> find(String lastName); 
                      List<Patient> find(String firstName, String lastName);
                      List<Patient> find(Date birthDate);
                      List<Patient> find(String firstName, String lastName, Date birthDate);
                  }
                  your implementations are terrible.

                  %
                  • 6. Re: search patient by patient id , first name , last name , date of birth
                    843785
                    I vote this the worst code I've seen in a long time, and I've seen some stinkers.
                    • 7. Re: search patient by patient id , first name , last name , date of birth
                      796254
                      DrLaszloJamf wrote:
                      I vote this the worst code I've seen in a long time, and I've seen some stinkers.
                      Agreed. Not worth saving. Not only would I delete the code, I'd reformat the hard drive it was written on and then wipe that clean. Then I'd take that hard drive out of the machine and recycle that.

                      %
                      • 8. Re: search patient by patient id , first name , last name , date of birth
                        843785
                        Hi,

                        I agree that this code is REALLY bad but unfortunetly, this won't help our friend.

                        A few advices:
                        -Instead of writing everytime the same code with little difference, try to write your code thinking: I won't write the exact same piece of code twice.
                        -You can build a query concatening different pieces and execute the result.
                        -NEVER put a NullPointerException catcher if you don't know exactly what you are doing, in this case, take them ALL off.
                        -NEVER return null from an Exception catcher if you don't know exactly what you are doing, for now, put a println for each of the Exception.

                        Only doing that, you should divide by 3 the size of your code and you should discover some errors that you have to fix.

                        Good luck,

                        MJalbert
                        • 9. Re: search patient by patient id , first name , last name , date of birth
                          796254
                          MJalbert wrote:
                          Hi,

                          I agree that this code is REALLY bad but unfortunetly, this won't help our friend.
                          I think starting with the interface I posted would help a great deal. There's more to this thread than simply mocking bad code.
                          A few advices:
                          -Instead of writing everytime the same code with little difference, try to write your code thinking: I won't write the exact same piece of code twice.
                          Good advice - Don't Repeat Yourself.
                          -You can build a query concatening different pieces and execute the result.
                          Why bother? There's a small, finite number of queries here. Why rebuild them each time? I'd make them final static Strings and use PreparedStatement.
                          -NEVER put a NullPointerException catcher if you don't know exactly what you are doing, in this case, take them ALL off.
                          Don't catch any exception that you don't intend to handle in some way.
                          -NEVER return null from an Exception catcher if you don't know exactly what you are doing, for now, put a println for each of the Exception.
                          Or, better yet, log it.

                          %
                          • 10. Re: search patient by patient id , first name , last name , date of birth
                            796254
                            Use a RowMapper interface to put rows into objects:
                            public interface RowMapper
                            {
                                Object map(ResultSet rs);
                            }
                            Resources are not closed properly anywhere. Close them in method scope in a finally block, in reverse order of creation, in individual try/catch blocks. (I encapsulate these once and for all in static utility methods.)

                            Don't make the DAO responsible for getting connections; pass those in.

                            %
                            • 11. Re: search patient by patient id , first name , last name , date of birth
                              843785
                              duffymo wrote:
                              Don't make the DAO responsible for getting connections; pass those in.
                              Inversion of Control/Dependency Injection?
                              • 12. Re: search patient by patient id , first name , last name , date of birth
                                796254
                                Yes.

                                A DAO can't know if it's being used as part of a larger transaction. The object that knows about the unit of work should be responsible for obtaining the connection, managing transaction logic, and cleaning up when it's finished. The way I do things, that means the service object.

                                %
                                • 13. Re: search patient by patient id , first name , last name , date of birth
                                  800625
                                  thanks.. i m trying to diffrent way...according to urs advice...
                                  • 14. Re: search patient by patient id , first name , last name , date of birth
                                    DrClap
                                    Here's another stinker chosen randomly from the code (most likely the cause of the NullPointerException):
                                    !firstname.equalsIgnoreCase(null)
                                    If you want to see whether a variable is null, just compare it to null:
                                    firstname != null
                                    And why "equalsIgnoreCase"? Did you suspect there were uppercase and lowercase nulls that might trip you up?
                                    1 2 Previous Next