没有为参数1指定值

时间:2017-08-05 17:42:34

标签: java jdbc

我收到的错误是“参数1没有特定值”。我想从UserId

显示登录用户的预订
    public ArrayList<booking> viewRestaurantsBooking() throws Exception {
    System.out.println("In viewRestaurantsBooking!");
    ArrayList<booking> myRestaurantsBookingList = new ArrayList<booking>();
    try {
        String selectStatement = "select * from famnection.bookrest where UserId=?";
        PreparedStatement prepStmt = con.prepareStatement(selectStatement);
        ResultSet rs = prepStmt.executeQuery();


        while (rs.next()) {
            System.out.println("Record Found!");
            booking myBookings = new booking();
            System.out.println("Restaurant Name=" + rs.getString("restName"));
            myBookings.setRestName(rs.getString("restName"));
            System.out.println("Booking Date=" + rs.getString("bookingdate"));
            myBookings.setBookingdate(rs.getDate("bookingdate"));
            System.out.println("Booking Time=" + rs.getString("bookingtime"));
            myBookings.setTime(rs.getString("bookingtime"));
            myRestaurantsBookingList.add(myBookings);

        }
    } catch (Exception ex) {
        throw new Exception("Error:" + ex.getMessage());
    }
    System.out.println("myRestaurantsList SIZE=" + myRestaurantsBookingList.size());
    return myRestaurantsBookingList;
}

1 个答案:

答案 0 :(得分:0)

您需要填写PreparedStatement中的参数

preparedStatement.setLong(1, someIdentifier)