【问题标题】:No value specified for parameter 1 [duplicate]没有为参数 1 指定值 [重复]
【发布时间】:2017-08-05 17:42:33
【问题描述】:

我收到错误消息“参数 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;
}

【问题讨论】:

  • 当您执行查询时,您认为它在 where 子句中寻找什么用户 ID?
  • 错误消息是excellent search keywords。不要不尊重和拼写错误。

标签: java jdbc


【解决方案1】:

PreparedStatement中需要填写参数

preparedStatement.setLong(1, someIdentifier)

【讨论】:

    猜你喜欢
    • 2017-06-25
    • 2020-03-16
    • 1970-01-01
    • 2012-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多