java - ResultSet not iterating values of specified column -


i've got method, returns value of resultset query via date object. snag that, in output, returns last value in particular column. how go this?

 public date gettime(){       date date = null;       dateformat format;        try {                class.forname("com.mysql.jdbc.driver");               connection con = drivermanager.getconnection(url, "root", "");                statement stmt = con.createstatement();                resultset result = stmt.executequery("select * error_log service_source = 'billbox' ");                while (result.next()) {  //retrieve data                   string ds = result.getstring("error_date");                   format = new simpledateformat("m/d/yyyy h:m:s a");                    date = (date)format.parse(ds);                  }               con.close();            } catch (exception ex) {               logger.getlogger(logdb.class.getname()).log(                              level.severe, null, ex);           }       return date;   } 

then in main method:

  public static void main(string args[]){               testa ea = new testa();       date ss = ea.gettime();       system.out.println(ss);   }  

but returns last value in query. how can print out other (the olders) along it?

you need fill list of dates query results. try :

  public list<date> gettime(){       list<date> dates = new arraylist<date>();       dateformat format;        try {            class.forname("com.mysql.jdbc.driver");           connection con = drivermanager.getconnection(url, "root", "");            statement stmt = con.createstatement();            resultset result = stmt.executequery("select * error_log service_source = 'billbox' ");            while (result.next()) {  //retrieve data               string ds = result.getstring("error_date");               format = new simpledateformat("m/d/yyyy h:m:s a");                dates.add((date)format.parse(ds));              }           con.close();        } catch (exception ex) {           logger.getlogger(logdb.class.getname()).log(                          level.severe, null, ex);       }       return dates;   } 

Comments