0

I have nearly 50 to 60 queries that need to their data output to be exported as Excels. Writing an Java to iterate all the rows of output and pushing to excel will be a tough task to maintain in future if the queries change. Is there an easy way to iterate only through the queries and not the data to output all output to excels. If there is a simple command in MySQL or any way in Java to do this export.

RandomWanderer
  • 621
  • 2
  • 9
  • 22
  • If they're all related, then you can consider writing an SQL View comprising of all the data. And create one POJO corresponding to the VIEW. – Sarath Chandra Aug 14 '15 at 21:36

1 Answers1

2

One simple way would be to get MySQL output in CSV format, and then import it to MS Excel.

From this answer, here's how you get MySQL's output in CSV:

SELECT order_id,product_name,qty
FROM orders
INTO OUTFILE '/tmp/orders.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n';
Community
  • 1
  • 1
John Bupit
  • 9,458
  • 6
  • 31
  • 68