1 16 package org.outerj.daisy.repository.query; 17 18 import java.util.Date ; 19 import java.text.SimpleDateFormat ; 20 21 24 public final class QueryHelper { 25 private static final String QUOTE = "'"; 26 27 public static String formatDateTime(Date date) { 28 SimpleDateFormat dateTimeFormat = new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss"); 29 return QUOTE + dateTimeFormat.format(date) + QUOTE; 30 } 31 32 public static String formatDate(Date date) { 33 SimpleDateFormat dateTimeFormat = new SimpleDateFormat ("yyyy-MM-dd"); 34 return QUOTE + dateTimeFormat.format(date) + QUOTE; 35 } 36 37 public static String formatTime(Date date) { 38 SimpleDateFormat dateTimeFormat = new SimpleDateFormat ("HH:mm:ss"); 39 return QUOTE + dateTimeFormat.format(date) + QUOTE; 40 } 41 42 public static String formatString(String text) { 43 StringBuffer escaped = new StringBuffer (text.length() + 10); 44 for (int i = 0; i < text.length(); i++) { 45 char c = text.charAt(i); 46 if (c == '\'') { 47 escaped.append("''"); 48 } else { 49 escaped.append(c); 50 } 51 } 52 return QUOTE + escaped + QUOTE; 53 } 54 55 } 56 | Popular Tags |