0

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

jarlh
  • 42,561
  • 8
  • 45
  • 63
oceano22
  • 463
  • 1
  • 5
  • 8

2 Answers2

0

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.

rahul shetty
  • 126
  • 7
0

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.

kfinity
  • 8,581
  • 1
  • 13
  • 20