java - Fetching data from Oracle database does not work first time -


we trying fetch data oracle db using preparedstatement. keeps fetching 0 records while same runs , fetches data when run pl/sql developer.

we found root cause while trying debug. while debugging code fetched 2 records properly.

we did temporary fix placing piece of code.

resultset rs = ps.executequery();     while(!rs.hasnext()){        ps.executequery();} 

this works. not best solution since results in unwanted db hit.it looks time issue. explicitly committed earlier transactions since can affect result of query.

what causing this. what's best way solve this?

the method quite big: i'll post parts here:

 private static boolean loadcommission(member member){         connection conn = getconnection("schema1");    //obtained through connection pool         //insertion table         conn.close();         conn conn2 = getconnection("schema2");    //obtained through connection pool         preparedstatement ps = conn2.preparestatement(sql);           //this sql combines data schema1                                    // , 2 db links          resultset rs = ps.executequery();          //business logic          conn2.close();         return true;        } 

thanks

we tried few more things yesterday. replaced second connection code direct jdbc connection so

  connection conn = drivermanager.getconnection(url, user, pass); 

this works. not sure if delay in getting connection pool or in completing previous transaction thought earlier.

if query selects materialized view, there may elapsed time before yield results (as materialized views not refresh instantly after commit, depending upon how they've been created).

if case, can resolve problem either selecting directly base table (or equivalent non-materialized views), or forcing materialized view refresh.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -