How to export database data, generate a csv and download?

Asked

Viewed 196 times

-2

I have a sales screen, where the user selects a customer, a product, the quantity and makes the purchase, this information is recorded in the database. I need a button on the sales screen that generates a report with all csv sales

  • I’m using Java and Spring boot

1 answer

1

A practical way would be to

SELECT * FROM vendas INTO OUTFILE 'C:/vendas.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n'

the FIELDS TERMINATED BY ',' determines the separation of columns with a "," (can be replaced)

the ENCLOSED BY '"' encapsulate the data with double quotes (can be overwritten or ignored)

and the LINES TERMINATED BY '\n' specifies that each line ends with a line break

Browser other questions tagged

You are not signed in. Login or sign up in order to post.