I'm new to MySql database and currently facing an issue with date format. I have tried few solutions from the internet but nothing worked. Hence I'm posting the question here.
I have a GUI where I'm providing the date as input, which is in "mm/dd/yyyy" format.
This is my code which contains the query:
public boolean fetchAPReportDomino(Date edDate, APReport apReport ){
Statement stmt=null;
ResultSet rs=null;
SimpleDateFormat sd= new SimpleDateFormat("MM/dd/yyyy");
SimpleDateFormat sd1=new SimpleDateFormat("yyyy-MM-dd");
String tempDate=sd.format(edDate);
if(getConnection()!=null){
try {
stmt= getConnection().createStatement();
String query="SELECT * FROM AP_Report where Edition Date = " + tempDate;
rs = stmt.executeQuery(query);
while (rs.next()) {
apReport.setRoomHumidity(rs.getInt("Room Humidity"));
apReport.setRoomTemperature(rs.getInt("Room Temperature"));
}
rs.close();
stmt.close();
} catch (SQLException ex) {
Logger.getLogger(DataService.class.getName()).log(Level.SEVERE, null, ex);
return false;
}
}
return true;
}
from the MySql workbench, I have tried changing the date field to "DATE", "TIMESTAMP", "DATETIME" datatypes. But nothing has helped.
Below is the error which Im seeing when I execute the code:
SEVERE: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Date = 02/14/2015' at line 1
Posting screenshot of table structure below:
http://prntscr.com/6qz5my

Edition Date(with space) unless it was created with backticks so you have to use it! - Jorge Campos