Home > Mobile >  Increment variable in JSP page
Increment variable in JSP page

Time:12-18

I am working on a flight reservation system where users can log into an account to make reservations.

In my sql database, I have a table called ticket where there is a column called seatnum. I have another table called aircraft and that has a column called seats.

In my jsp page, I want to assign a random seat number to a person buying a ticket, but I can only assign so many seats before the seats in the aircraft table gets full.

I want to declare a global counter for the number of seats I assign to a particular flight, but my counter keeps being reset to 0 but I can't declare a static variable in a jsp. What should I do instead?


CREATE TABLE `ticket` (
  `cid` int,
  `flight_num` int,
  `ticket_num` int NOT NULL AUTO_INCREMENT,
  `seatnum` int, 
PRIMARY KEY (`ticket_num`),
FOREIGN KEY (`flight_num`) REFERENCES flight (`flight_num`) ON UPDATE CASCADE ON DELETE CASCADE,
FOREIGN KEY (`cid`) REFERENCES user (`cid`) ON UPDATE CASCADE ON DELETE CASCADE
) 

CREATE TABLE `aircraft` (
    `2letterid` varchar(2),
    `aircraft_num` int,
    `seats` int,
PRIMARY KEY (`2letterid`, `aircraft_num`),
FOREIGN KEY(`2letterid`) REFERENCES `airline` (`2letterid`)
) 

int counter = 0;
String seats = "select seats from flight join aircraft(flight_num) "  
                "where flight_num = "   flightNum;

if (counter > seats) {
enter a waiting list
}

CodePudding user response:

You can store the counter in a hidden field or in the session.

  • Related