I have a column field called StartDate
in MySQL of Date
datatype. In my application, I defined a way to show the current date onn my page like this.
String today = CoreUtil.parseDate(new Date());
This basically returns the date in YYYY-MM-DD
format and stored it in a string which is fine.
Now, I would like to pass this value into a function that inserts the value to the column StartDate
.
The function I declared is as follow:
public void insert_update(String nodeid,String ts,Date startdt,Date enddt,int enable)
I am calling this function and passing the value today
to it like below:
fileFacade.insert_update(...,....,today,....,...);
Now I am not an expert in this date thingy and seeing it wouldn't allow me to pass the value as I defined it as Date parameter, how should I handle this issue?
Should I convert it back to Date format and pass the value or does MySQL allow insertion of string value into a Date datatype column?
I just want to store the value in my table in YYYY-MM-DD
format.
edit:
My function:
public void insert_update(String nodeid,String ts,Date startdt,Date enddt,int enable){
try {
// UrlLink attr = em.find(UrlLink.class,n);
String sql="UPDATE urllink SET STARTDT="+startdt+",ENDDT="+enddt+",ENABLE="+enable+"WHERE URL='f0="+nodeid+"&ts="+ts + "'";
em.createNativeQuery(sql).executeUpdate();
}catch (Exception e) {
e.printStackTrace();
}
}