/**
* $Id:DbUtil.java $
*
* Copyright 2004 ~ 2005 JingFei International Cooperation LTD. All rights reserved.
*
*/
package com.jfimagine.utils.commonutil;
import java.util.Date;
import java.sql.ResultSet;
import com.jfimagine.utils.commonutil.CommonUtil;
/**
* Database utilities for data processing
*
* @author CookieMaker
*
* @version $Revision: 1.00 $
*/
public class DbUtil{
/**
* Convert a java.util.Date to a java.sql.Date
*
* @param d A java.util.Date value to be converted
*
* @return a java.sql.Date value, null if input is also null
*
*/
public static java.sql.Date d2sqld(Date d){
if (d==null)
return null;
else
return new java.sql.Date(d.getTime());
}
/**
* Convert a java.sql.Date to a java.util.Date
*
* @param d A java.sql.Date value to be converted
*
* @return a java.util.Date value, null if input is also null
*
*/
public static Date sqld2d(java.sql.Date d){
if (d==null)
return null;
else
return new Date(d.getTime());
}
/**
* Convert a Date to a SQL Value String
*
* @param d A date value to be converted
*
* @return a String value represents a value formmatted as 'YYYY-MM-DD' and appended two quotation marks, null if input is null
*
*/
public static String d2sql(Date d){
String s;
s =CommonUtil.d2s(d);
if (s==null || s==""){
s =null;
}else{
s ="'"+s+"'";
}
return s;
}
/**
* Convert a Datetime to a SQL Value String
*
* @param d A datetime value to be converted
*
* @return a String value represents a value formmatted as 'YYYY-MM-DD hh:mm:ss' and appended two quotation marks, null if input is null
*
*/
public static String dt2sql(Date d){
String s;
s =CommonUtil.dt2s(d);
if (s==null || s==""){
s =null;
}else{
s ="'"+s+"'";
}
return s;
}
}