I am converting my date param from "yyyy-MM-dd" to "yyyy/MM/dd" using the below code
String dateParam = new SimpleDateFormat("yyyy/MM/dd").format(inpDate);
where inpDate
= 2021-05-05 (date type)
When I came across a line of resultSet, it traverse next directly to catch statement, before checking the if
condition and I facing an exception
Literal does not match format string
I tried all possibilities but unable to get rid of this exception.
public boolean dateInfo (Date inpDate, Connection conn)
{
StringBuilder queryStr = new StringBuilder();
ResultSet resultSet = null;
PreparedStatement ps = null;
String dateParam = new SimpleDateFormat("yyyy/MM/dd").format(inpDate);
queryStr.append("SELECT * FROM TABLE WHERE DB_DATE>= ?");
try{
ps = conn.prepareStatement(queryString.toString());
ps.setString(1,dateParam);
resultSet = ps.executeQuery();
if(resultSet.next())
{
return true;
}
}
catch(SQLException e)
{
e.printStackTrace();
}
finally {
DbAccessUtility.closeStatements(ps,resultSet);
}
return false;
}