如何在eclipse中更改sysdate格式的查询?

时间:2015-12-08 09:14:00

标签: java eclipse

Date today = new Date();
SimpleDateFormat df = new SimpleDateFormat ("dd/MM/yy");
String date = df.format(today);
System.out.println(date);
PreparedStatement sql = con.prepareStatement("select count(*), name, status from tablename where file_date = date group by name, status");
ResultSet rs = sql.executeQuery();
However, the sysdate format in SQL is dd/MM/yy

但Eclipse中的日期格式为yyyy-MM-dd HH:mm:ss.fff

如何在查询中对其进行转换,以便我可以获得dd/MM/yy格式?

1 个答案:

答案 0 :(得分:2)

如果传递一个真正的SQL日期,请不要担心日期的内部字符串表示。

PreparedStatement sql = con.prepareStatement("select count(*), name, status from tablename where file_date = ? group by file_name, status");

sql.setDate(1, new java.sql.Date(new java.util.Date().getTime());