seema bhoir

seema bhoir

  • NA
  • 10
  • 2.6k

Handle null string in Java

Apr 7 2014 3:37 AM

I am reading CSV file and inserting into table.but when I get completdate as null I want to insert default date.i checked this

//if(COMPLETEDATE == "null")

if(COMPLETEDATE == null)

{

css.setString(24, "2013-06-12 00:00:00.0");

}

else{

css.setString(24, COMPLETEDATE);

} 


    public void ImportCSV()

 {
        String csvFile = "C:\\seema\\CSV Files\\2013\\August\\15.csv";
        BufferedReader br = null;
        String line = "";
        String cvsSplitBy = ",";
        String PRODLINE,EMPID,EMPFNAME,SHIFT,STATIONID,CURWKDATE,OPCODE,OPDESC,STARTWORKTIME,ENDWORKTIME,PIECECNT,
               BUNDLECNT,PIECERATE,SAM,SKILLLEVEL,DAILYBONUS,NORMALRATE,OVERTIMERATE,WORKDURATION,MONO,DESIGNCODE,
               DESIGNCOLOR,DESIGNSIZE,COMPLETEDATE;
   
        int i=0;
        try {
        br = new BufferedReader(new FileReader(csvFile));
        while ((line = br.readLine()) != null) {
          try {
            PreparedStatement css = null;
            css= conn.prepareStatement("exec    uspInsertEWLProduction ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?");
   
            String[] country = line.split(",");
   
            PRODLINE=country[0];
            EMPID=country[1];
            EMPFNAME =country[2];
            SHIFT=country[3];
            STATIONID=country[4];
            CURWKDATE =country[5];
            OPCODE=country[6];
            OPDESC=country[7];
            STARTWORKTIME =country[8];
            ENDWORKTIME=country[9];
            PIECECNT=country[10];
            BUNDLECNT =country[11];
            PIECERATE=country[12];
            SAM=country[13];
            SKILLLEVEL =country[14];
            DAILYBONUS=country[15];
            NORMALRATE=country[16];
            OVERTIMERATE =country[17];
            WORKDURATION=country[18];
            MONO=country[19];
            DESIGNCODE =country[20];
            DESIGNCOLOR=country[21];
            DESIGNSIZE=country[22];
            COMPLETEDATE =country[23];
   
            if(i!=0) {
               css.setString(1, PRODLINE);   
               css.setString(2, EMPID);
               css.setString(3, EMPFNAME);
               css.setString(4, SHIFT);
               css.setString(5, STATIONID);
               css.setString(6, CURWKDATE);
               css.setString(7, OPCODE);   
               css.setString(8, OPDESC);
               css.setString(9, STARTWORKTIME);
               css.setString(10, ENDWORKTIME);
               css.setString(11, PIECECNT); 
               css.setString(12, BUNDLECNT);
               css.setString(13, PIECERATE);
               css.setString(14, SAM);
               css.setString(15, SKILLLEVEL);
               css.setString(16, DAILYBONUS);
               css.setString(17, NORMALRATE);
               css.setString(18, OVERTIMERATE);
               css.setString(19, WORKDURATION);
               css.setString(20, MONO);
               css.setString(21, DESIGNCODE);
               css.setString(22, DESIGNCOLOR);
               css.setString(23, DESIGNSIZE);
   
               if(COMPLETEDATE == null) {
                  css.setString(24, "2013-06-12 00:00:00.0");
               } else {
                  css.setString(24, COMPLETEDATE);
               }
             }
             css.executeUpdate();
           } catch (Exception e) {
             e.printStackTrace();
           }
           i++;
         }
         JOptionPane.showMessageDialog(null, "Data Imported Successfully");
       } catch (FileNotFoundException e) {
         e.printStackTrace();
       }
    }
 
The problem is else part is never get executed eventhough copmletedate is null. Any solution?

 I am reading from CSV file and in CSV file copmletedate is null


Answers (1)