Java, use array instead of SQL SELECT -


i have 1 script fetches around 25.000 different id values , uses them make changes in other table. programmer created code searches id (dialid in code) through table of 10 million records (line 3) , every query in loop executing around 1 second. idea fetch last 30 days of records sql , put array , check array.

and question is, how in java? in_array function? i'm solid in php, beginner in java code...


private integer getdialid(int predictiveid) {  integer dialid = null;  stringbuilder sql = new stringbuilder("select dialid dial predictive_dialid=");     sql.append(predictiveid); //this predictiveid calculated in other part of code     resultset rsdialid = null;      statement s1 = null;     try {          s1 = oracle.getconn().createstatement(resultset.type_scroll_insensitive,                 resultset.concur_updatable, resultset.close_cursors_at_commit);          rsdialid = s1.executequery(string.valueof(sql));         if (rsdialid.next()) {             dialid = rsdialid.getint("dialid");         }     } catch (sqlexception ex) {         logger.getlogger(mediatelcdrsync.class.getname()).log(level.severe, null, ex);     } {         try {             if (s1 != null) {                 s1.close();             }             if (rsdialid != null) {                 rsdialid.close();             }         } catch (sqlexception ex) {             logger.getlogger(mediatelcdrsync.class.getname()).log(level.severe, null, ex);         }     }      system.out.println("dialid = " + dialid);     return dialid; } 

thnx

if have performance problem i'd start see why query takes 1 second per execution, if it's database time because dial table not have , index on predictive_dialid column can little @ java level. anyway jdbc code reveals problems when used oracle database. biggest issue hardcoding query parameter causing oracle re"hard parse" query every time; second (minor one) resultset scrollable , updatable while need load first row. if want make little modification code should change somethig pseudo code:

        preparedstatement ps =connection.preparestatement("select dialid dial predictive_dialid=?");          (int i=0;i<10;i++) {//your 25000 loop elements 1               //this shoudl start of body of getdialid function takes prepared statement             ps.setint(1, i);             resultset rs=ps.executequery();             if (rs.next()) {                 rs.getint("dialid");                 }             rs.close();             //your getdialid end here          }         ps.close(); 

with minimal java solution should note performance increase, must chek performance of single query since if there missing index cand little @ java code.

another solution, more complicated, to create temporart table, fill 25000 predictiveid values , issue query joins dial , temporary table; 1 resultset(and 1 query) can find dialid need. jdbc batch insert temp table speeds insertion time noticeably.


Comments