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

Connect via SSH without a password from MacOS to Linux with an SSHKEY

Read and Write Files in Java

Install Mac OS on windows laptop