I want to change date format yyyy-mm-dd hh:mm:ss.SSS ( which is stored in database in string format) to mm/dd/yyyy for their comparison
while(rs.next())
A few notes
reportBean becomes ReportBeanrs.getString("customer_code") rather than rs.getString(3)myDate1 becomes closeDateSystem.out.println()stmt.close() moves within a finally blockException, e.g. log.error("Invalid Date Parser Exception", e);Some specific pointers:
new SimpleDateFormat("yyyy-mm-dd hh:mm:ss.SSSSSS") // as already noted, mm is the format for minute, MM is the format for month
myDate4 = myDateFormat.format(myDate5); // invalid as you are asigning a String to a Date
if(myDate1.after(myDate4)) // irrelevant as both if & else block execute the same code
rs.close() // not necessary as closed when `Statement` is closed
see Javadoc
Are you sure that your database schema is all varchar columns? I'd recommend that you fixed that if its the case. Otherwise you can call rs.getDate() instead.
You have set myDateFormat1 to "yyyy-mm-dd hh:mm:ss.SSSSSS". I think the first mm should be in uppercase.
I recommend you check your format strings with the documentation if SimpleDateFormat.