Sunday, March 30, 2014

sql file return list and singleRow return means no return list AND action class

save = insert query
edit = update query


**sql file return list and singleRow return means no return list  AND java action class  :

sql query :file name :patientAppoinmentListsql.java
/////////////////////////////////////////////////////


// Start zip code .......................................
  public List<M00LkpInfo>  getDbzipCodeList() {
   
  List<M00LkpInfo> internelzipCodedbList=new ArrayList<M00LkpInfo>(); //change this Line

       String value = null;
       boolean flag = true;
       String query = "";

       // get data base connection
       con = dbc.connectDB();

       if (con == null) {
           flag = false;
       }


       if (flag) {

           try {
               st = con.createStatement();

               query = " select govt_post_code from hr_postoffice order by govt_post_code";
             

                System.out.println(query);

               rs = st.executeQuery(query);

               
               while (rs.next()) {
                M00LkpInfo m00LkpInfo = new M00LkpInfo();
               
             
                m00LkpInfo.setPost_code(rs.getString("govt_post_code"));
                //m00LkpInfo.setPost_name(rs.getString("POST_NAME"));
                internelzipCodedbList.add(m00LkpInfo);
               
               // System.out.println(admittedDoctorInfo.getkipd_id());
               }


           } catch (SQLException sq) {
               sq.printStackTrace();
           } finally {
               try {
                   rs.close();
                   st.close();
                   con.close();
               } catch (SQLException ex) {
                   ex.printStackTrace();
               }
           }
       }

       return internelzipCodedbList;
   }

//End zip code.........................................
  

  
// Start against zip code(no return list. so return single row) set state and city  {self note }.......................................
  public M00LkpInfo getZipCodeNoListReturn(String zipCodeSent){
  boolean flag = true;
      String query = "";
      M00LkpInfo raceInfo=new M00LkpInfo();  //change this Line
      // get data base connection
      con = dbc.connectDB();

      if (con == null) {
          flag = false;
      }

      // ---------- Get patient information of a doctor ----------
      if (flag) {
          try {
              st = con.createStatement();
            //  query = "SELECT GRP_ID,LKP_ID,LKP_NAME,SN FROM M00_LKP WHERE GRP_ID=7 ORDER BY 3";
              
             // query = "select LKP_ID, LKP_NAME from M00_LKP where GRP_ID =7";
              
            query = " select  a.govt_post_code,b.city_name city_name, c.province_name state  " +
            "from hr_postoffice a ,hr_city b ,hr_province c " +
            "where  c.province_id = b.province_id " +
            "and b.city_code = a.city_code  " +
            "and   a.govt_post_code = '"+zipCodeSent+"' ";
             

              System.out.println("SQL : " + query);

              rs = st.executeQuery(query);

              while (rs.next()) {
                     
              raceInfo.setCity_name(rs.getString("city_name"));
              raceInfo.setState(rs.getString("state"));             
              
            //  raceList.add(raceInfo);
              }

          } catch (SQLException sq) {
              sq.printStackTrace();
          } finally {
              try {
                  rs.close();
                  st.close();
                  con.close();
              } catch (SQLException ex) {
                  ex.printStackTrace();
              }
          }

      }

    return raceInfo;
   }
  

// End against zip code(no return list. so return single row) set state and city  {self note }.......................................








########################################################
########################################################
########################################################
########################################################
LoadAction.java
///////////////////////////////////////////////////////

List<M00LkpInfo> internelzipCodedbList=new ArrayList<M00LkpInfo>(); // change this line
public String zcodeList(){
    PatientAppointmentList patientAppointmentList = new PatientAppointmentList();
    internelzipCodedbList = patientAppointmentList.getDbzipCodeList();

     return "zcodeList";

}

















####################################################
 // set city and state against zipcode start [For sql query single row return ].........
private String zipCodeSent;  
 M00LkpInfo noListoneRow=new M00LkpInfo();  // [For sql query single row return ] so change this line .........
 public String zipcode(){
 PatientAppointmentList patientAppointmentList = new PatientAppointmentList();
noListoneRow = patientAppointmentList.getZipCodeNoListReturn(zipCodeSent);
return "zipcode";
 }





 // set city and state against zipcode end [For sql query single row return ].........


No comments:

Post a Comment