I think you misunderstand what it means to be a developer. You actually *write* code, you don't get it presented to you on a plate.
So to retrieve data from the database, use JDBC or for example Hibernate.
To store data in an excel sheet, either do it the easy way and store the data in a comma separated values file (CSV) or a tab delimited file, or else you will have to use an api like POI to write the excel sheet.
http://jakarta.apache.org/poi/index.html
http://jakarta.apache.org/poi/hssf/quick-guide.html