Convert Date object to Mysql Date Format


public static String toMysqlDateStr(Date date){
if (date==null) return "NULL";
SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return sqlValueWithQuotas(sdf.format(date));
}

public static String sqlValueWithQuotas(Object obj){
if ( obj == null ) return "NULL";

String str = obj.toString();
str.replaceAll("'", "\\'");
str = '\''+str+'\'';

return str;

}

Comments

Anonymous said…
Thank you, this is really what I need for this moment :P

Popular posts from this blog

Get Remote IP Address In Axis SOAP Server

Escape HTML and XML in Java

Java HTTP GET POST