java - Efficiently Handling a ResultSet -


i'm trying fetch results database using jdbc connectivity. result set made of more 60,000 rows i'm iterating build list comparison list object of similar size. problem while approach gives correct result, it's slow. ideas 2 how speed ? code sample given below:

public class performancetest {      //create connection     connection getconnection(string uname, string pwd, string url) throws classnotfoundexception, sqlexception     {         properties info = new properties();         info.setproperty("user", uname);         info.setproperty("password", pwd);         try         {             class.forname("oracle.jdbc.driver.oracledriver");             return drivermanager.getconnection(url, info);         }          catch (classnotfoundexception e)         {             throw e;         }         catch (sqlexception e)         {            throw e;         }     }      //fetch records , put them in map schema name key , table name value     public list<string> fetchrecords(connection conn, string sql) throws sqlexception     {         statement stmt;         resultset rs;         string tablename;         list<string> tablelist;         long starttime;         int i=0;         if(conn!=null)         {             try             {                 tablelist = new arraylist<string>();                 stmt = conn.createstatement();                 rs = stmt.executequery(sql);                 starttime = system.currenttimemillis();                 while(rs.next())                 {                     system.out.println(++i);                     tablename = rs.getstring(1);                     tablelist.add(tablename);                 }                  system.out.println("running time: " + (system.currenttimemillis() - starttime)/1000 + " seconds");                 return tablelist;             }             catch(sqlexception e)             {                 throw e;             }         }         else         {             return null;         }      }      public boolean main() throws classnotfoundexception, sqlexception     {         string url = "jdbc:oracle:thin:@xxxxxx:1521:xxxxx";         connection conn = getconnection("", "", url);         string sql = "select  table_name user_tables";         long starttime;         boolean result;         list<string> l1 = fetchrecords(conn, sql);         list<string> l2 = new arraylist<string>(l1);         //l2.add("1");         starttime = system.currenttimemillis();         result = l2.containsall(l1);         system.out.println("running time: " + (system.currenttimemillis() - starttime)/1000 + " seconds");         return result;     } } 


Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -