这是查询方法://通过出发地、目的地、发车日期 查询车次 public List<Train> queryAll(String toAddress,String fromAddress,Date startDate){ String sql ="select * from tts_traininfo where toAddress like ? and fromAddress like ? and startDate like TO_DATE(?,'yyyy-mm-dd hh24:mi:ss')"; List<Train> list = new ArrayList<>(); Connection conn = DBConnection.getConnection(); try { PreparedStatement pstm = conn.prepareStatement(sql); pstm.setString(1, "%" + toAddress + "%"); pstm.setString(2, "%" + fromAddress + "%"); pstm.setString(3, "%" + startDate + "%"); ResultSet rs = pstm.executeQuery(); if (rs.next()) { Train train = new Train(rs.getInt(1), rs.getString(2), rs.getString(3), rs.getString(4), rs.getDate(5), rs.getDate(6), rs.getDouble(7)); list.add(train); } } catch (SQLException e) { e.printStackTrace(); } return list; }这是测试方法: @Test public void queryAll() { Scanner sc = new Scanner(System.in); System.out.println("请输入出发地:"); String toAddress = sc.nextLine(); System.out.println("请输入目的地:"); String fromAddress = sc.nextLine(); System.out.println("请输入发车日期:"); String sDate = sc.nextLine(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd"); Date date; try { date = sdf.parse(sDate); Date startDate = new java.sql.Date(date.getTime()); System.out.println(startDate); List<Train> list = tot.queryAll(toAddress, fromAddress, startDate); System.out.println(list); list.forEach((item) -> { System.out.println( item.getId() + "," + item.getTrainId() + "," + item.getToAddress() + "," + item.getFromAddress() + "," + item.getStartDate() + "," + item.getStartTime() + "," + item.getFares()); }); } catch (ParseException e) { e.printStackTrace(); } }输入目的地、出发地、还有时间后 报错请输入出发地:北京请输入目的地:上海请输入发车日期:2018-06-082018-01-08java.sql.SQLDataException: ORA-01841: (完整) 年份值必须介于 -4713 和 +9999 之间, 且不为 0求大神解决!!! 急急急急!!!
添加回答
举报
0/150
提交
取消