简体   繁体   中英

SQL jdbc query support required

There is a schema Flight(flightnumber, processed int) pilot(pilot_number, pilot_name)

To assign a pilot to the flight I first scan the flight table and for each flight number I did a query(inside method called Assignment(Flight flight).

public void select(){
      Flight flight = new flight();
      query = “select * from flight”;
then
//for each flight do some query
public void Assignment(Flight flight){
     //query with flightnumber = flight.flightnumber
}

Now the requirement has changed. A new column processed is added to Flight table.
I have to use Assignment() (now it has no arguments) and find the first unprocessed flight in flights to do some query and then set processed value to 1.

database sql .. java jdbc How do I do this? Thank you for reading my question. Hope I was clear.

One way to handle this

We can have filter criteria in the select statement

SELECT * FROM flight
WHERE is_processed =0 AND rownum=1 
//returns only one record with the status of `is_processed` as 0 

After the assignment update the is_processed value to 1 for the returned flight details. //do above actions under same transaction

Other way is to combine these steps in a stored-procedure and call the procedure from your java code

Let me know if I misunderstood your question

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM