简体   繁体   English

需要SQL jdbc查询支持

[英]SQL jdbc query support required

There is a schema Flight(flightnumber, processed int) pilot(pilot_number, pilot_name) 有一个模式Flight(flightnumber,int)飞行员(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). 为了分配飞行员到航班,我首先扫描航班表,并为每个航班号进行查询(在名为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. 已处理的新列将添加到Flight表中。
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. 我必须使用Assignment()(现在它没有参数)并找到flight中的第一个未处理的航班来进行一些查询,然后将处理后的值设置为1。

database sql .. java jdbc How do I do this? 数据库sql .. java jdbc我该怎么做? 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语句中有过滤条件

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. 分配后,将返回的航班详细信息的is_processed值更新为1。 //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 另一种方法是将这些步骤组合到存储过程中,然后从Java代码中调用该过程

Let me know if I misunderstood your question 让我知道我是否误解了您的问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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