我想在两个不同的时间戳
之间选择数据库中的所有值<form action="index.jsp" METHOD="POST" >
<table border="2" style="border-collapse: collapse;">
<tr>
<td>SELECT THE TO DATE</td><td><input name="dt" type="text" id="datepicker" readonly="readonly" size="20"/></td>
<td >SELECT FROM DATE </td><td><input name="dt1" type="text" id="datepicker2" readonly="readonly" size="20"/></td>
</tr>
<tr><td colspan="4"><input type="submit" value="SAVE"><td></tr>
</table>
</form>
这是第二页,我正在重温价值。
String Date1=request.getParameter("dt");
SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy");
java.util.Date date = sdf.parse(Date1);
java.sql.Timestamp sqlStartDate = new java.sql.Timestamp(date.getTime());//2015-04-26 00:00:00.0
String Date2=request.getParameter("dt1");
java.util.Date date1=sdf.parse(Date2);
java.sql.Timestamp sqlEndDate = new java.sql.Timestamp(date1.getTime());//2015-06-26 00:00:00.0
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:xe", "RCC", "RCC@123");
PreparedStatement pst=con.prepareStatement("Select * from TBLTENDERS where TSTATUSDATE between (TO_TIMESTAMP(?,'dd-mm-yyyy')) and (TO_TIMESTAMP(?,'dd-mm-yyyy'))");
pst.setTimestamp(1, sqlStartDate);
pst.setTimestamp(2,sqlEndDate);
ResultSet rest=pst.executeQuery();
我在查询中收到错误&#34; java.sql.SQLException:ORA-01830:日期格式图片在转换整个输入字符串&#34;之前结束。所以任何人都可以帮我查询。
答案 0 :(得分:1)
从查询中删除to_timestamp,因为您的参数已经是时间戳:
PreparedStatement pst=con.prepareStatement("Select * from TBLTENDERS where TSTATUSDATE between ? and ?");