简体   繁体   中英

File.csv size from select oracle

I implemented a java class that given a select sql oracle creates a file (csv) (temporary) and sends it via e-mail with a scheduled process. I have a problem: the mail client has a send and receive size. How can I, given the select know how big my file will be? What other checks do you recommend to avoid generating the file and then not being able to send / receive?

Many thanks in advance

When you do the temp file

File tempFile;

Just do

double size=tempFile.lenght();

will return the file size in bytes and you can check it before you send with the email.

If you want to estimate the size of the SQL resultset before you generate the file, that's a little tricky. People have asked similar questions before - one , two .

I'd suggest doing what this answer says: do a SELECT COUNT(*) with your query to get a rowcount. (You might also be able to do this with a cursor or your ResultSet object, depending on how you're doing this.) Then multiply your rowcount by your average row size, which you can do by looking at some of your generated CSV files and calculating the size divided by the number of rows.

If this is a common problem, you might also consider zipping your CSV files . They usually compress very well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM