我本来的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>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通用的 ?
hibernate可以屏蔽差异,
但我觉得它还是在内部对不同的数据库做了不同的处理,只是对开发人员透明而已
问题是这里 不能用 HIBERNATE
只有 上面类似的 语句 行不行 ?
数据库里面存的是 Date型select * from aaa where updatedate>{d ?}
(注意{d }仅限yyyy-mm-dd格式)
你这里 指的是 日期格式还是字符串格式的?
我本来也是 字符串格式的
好像不行额 select * from aaa where updatedate>'2012-11-11'
PreparedStatement ps = conn.prepareStatement("select * from junzheng_dual where dateval > {d ?}");
ps.setString(1, "2012-05-12");这要是不行我去吃ANSI SQL-2标准