日期:2014-05-20  浏览次数:20614 次

时间格式 SQLSERVER ORACLE两个数据库通用
我本来的SQL 语句大概是这么写的
select * from aaa where updatedate>DateHelper.formatDateToString(date,'yyyy-MM-dd')
public static String formatDateToString(Date date, String pattern)
{
if (date == null)
{
return "";
}
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
return sdf.format(date);
}
就是 一个 时间字符串
但我数据库 换 ORACLE版本的时候就出现问题
只有把方法改成

public static String formatDateToOracle(Date date, String pattern)
{
if (date == null)
{
return "";
}
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
return "to_date('"+sdf.format(date)+"','"+pattern+"')";
}
有没有一种写法是不用改方法的 
直接 可以做到 ORALCE 和 SQLSERVER通用的 ?

------解决方案--------------------
引用:
你这里 指的是 日期格式还是字符串格式的?
我本来也是 字符串格式的
好像不行额  select * from aaa where updatedate>'2012-11-11'

你误会了,我是把{d }放到sql代码段里的啊


PreparedStatement ps = conn.prepareStatement("select * from junzheng_dual where dateval > {d ?}");
ps.setString(1, "2012-05-12");

这要是不行我去吃ANSI SQL-2标准