我本来的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通用的 ?

解决方案 »

  1.   

    这是各个数据库的区别啦;
    hibernate可以屏蔽差异,
    但我觉得它还是在内部对不同的数据库做了不同的处理,只是对开发人员透明而已
      

  2.   

    不是说了么,可以使用hibernate之类的组件= =...
      

  3.   

    不好意思 刚才 没反应过来
    问题是这里 不能用 HIBERNATE
    只有 上面类似的 语句 行不行 ?
      

  4.   

    你db里updatedate字段是VARCHAR型还是Date型的?
      

  5.   

    至于这么麻烦么select * from aaa where updatedate>{d ?}(注意{d }仅限yyyy-mm-dd格式)只要你还用jdbc,这个语法通行所有数据库。
      

  6.   


    数据库里面存的是 Date型select * from aaa where updatedate>{d ?}
    (注意{d }仅限yyyy-mm-dd格式)
    你这里 指的是 日期格式还是字符串格式的?
    我本来也是 字符串格式的
    好像不行额  select * from aaa where updatedate>'2012-11-11'
      

  7.   

    你误会了,我是把{d }放到sql代码段里的啊
    PreparedStatement ps = conn.prepareStatement("select * from junzheng_dual where dateval > {d ?}");
    ps.setString(1, "2012-05-12");这要是不行我去吃ANSI SQL-2标准