简体   繁体   English

Oracle SQL 在同一表上连续命中随机不获取数据

[英]Oracle SQL randomly not fetch data on continous hit on the same table

I am working on Oracle sql queries with java code in Oracle ADF.我正在使用 Oracle ADF 中的 java 代码处理 Oracle sql 查询。 I have written piece of code as below我写了一段代码如下

public String getValue(Connection cn, String val1) throws SQLException {
    String sql = "select price FROM table1 WHERE val1= ?";
    PreparedStatement ps = cn.prepareStatement(sql);
    ps.setString(1, val1);
    ResultSet rs = ps.executeQuery();
    try
    {
        
        if(rs.next()){
            return rs.getString("price");
        }
        else{
            System.out.println("price is null");
        }
    }catch(Exception e){
        e.printStackTrace();
        throw e;
    }
    finally{
        rs.close();
        ps.close();
        
        }
    return null;
    }

I am hitting this method more than 100000 times.我使用这种方法超过 100000 次。 in these many times, val1 is repeating.在这么多次中,val1 是重复的。 so for same val1, in some of the cases, its price is fetched, but in some cases, its not.所以对于同一个 val1,在某些情况下,它的价格是被获取的,但在某些情况下,它不是。

 val1 is in the method --->1
 price 3
 val1 is in the method --->2
 price 5
 val1 is in the method --->1
 price 3
 val1 is in the method --->1
 price null ---> here in previous hit, for 1 - it has fetched price 3, but in this it has fetched null for the same value 1.
 val1 is in the method --->1
 price 3

I have tried other approaches like,我尝试过其他方法,例如,

1.  String sql = "select price FROM table1 WHERE val1='"+val1+"'";
2. I have checked that all the resources are getting closed or not, but could not find any issue.

I request you to help in this matter.我请求你在这件事上提供帮助。

Thanks & Regards, Shaili.谢谢和问候,Shaili。

Try apply synchronized keyword in your get value method.尝试在您的获取值方法中应用同步关键字。 Another reason maybe in database have 2 row with value val1 = 1另一个原因可能在数据库中有 2 行值 val1 = 1

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

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