I'm a java newbie but I'm not sure what I'm doing wrong. When I try to retrieve the last two dates from a database it only displays the year(while in mysql the same command provides the correct result).
Mysql command: SELECT DISTINCT date From fundanalysis ORDER BY date DESC LIMIT 2
Expected result:
2011-06-13
2011-06-08
Here's my java code:
preparedStatement = con.prepareStatement("SELECT DISTINCT date From fundanalysis ORDER BY date DESC LIMIT 2");
ResultSet numberofrowsresultset = preparedStatement.executeQuery();
numberofrowsresultset.next();
// most recent date
currentdate.add(numberofrowsresultset.getInt("date"));
System.out.print(numberofrowsresultset.getInt("date"));
numberofrowsresultset.next();
// last date before most recent
currentdate.add(numberofrowsresultset.getInt("date"));
return currentdate;
The final result is: [2011, 2011]
I basically want the exact same result as I get when I run the mysql query because I have to submit it as is to do another query later in the program.
pls help!