Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Writing data to excel from database using java

 
Sanju Sanjana
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello ,
I had an assignment goal was as below and i was struck in between !! I have used netbeans editor and Apache POI libaries for my program
1) Need to create a GUI which has a text label/ Button where we write down the queries in the text field and once when the button is pressed the result of that certain query should be exported to Excel sheet !!
2) Condition for the excel sheet is that, if the data in the excel sheet exceeds 60MB, it should create an another excel sheet and copy the remaining data and so forth

i have created a abc.java class which contains the db connections and a jframe.java which has a textAreafield and a button. I wanted to call jframe.java, to a abc.java class so that, the text i type in the textArea field will be received as query in my abc.java class I wanted my program such that, when i click on the button my query should be executed !! Please help

My code for abc.java is as follows:
 
Greg Charles
Sheriff
Posts: 3002
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to Java Ranch!

You've put all your code into the main() method of abc.java, which makes it seem like you want to execute it as a standalone program. Also, abc is just a terrible name for a class. Class names should start with a capital letter and should be short but descriptive of what the class is for. This isn't a detail you want to push aside until later, because proper naming of classes, methods, and variables is fundamental to good program design.

OK, the way I see it, your JButton should have an ActionListener added to it. The implementation of that ActionListener should create an instance of abc, or whatever name you come up with, and call a method on it, passing in the text from the text area. That method should just be a regular public method of the abc class, not its static main method. You could return a status from the method, and display that in your GUI.
 
Sanju Sanjana
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you
I have just tried my code as a sample one so i didn't care much about the name convention ... Anyway thanz for the sugguestion I will go ahead with your idea and try it !!



 
Sanju Sanjana
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm dealing with large amount data which is to be saved to excel files. I have written the code to write the data into excel but how to find the size of excel workbook ???
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you mean after the file has been written? The File class has a method for that.
 
Sanju Sanjana
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My program needs to generate an excel worksheet automatically. If the data written into that sheet exceeds 5MB, it needs to create an new workbook and write the remaining data into the new worksheet and so on !! I have written the code to write down the data into excel and i have to know the size of my sheet in the case of bulk data ....
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you don't want to write the workbook to a file in order to figure out how large it is, write it to a byte[] in memory and see how large that is. You'd use a ByteArrayOutputStream for that.
 
Naveen doddo
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Once the ResultSet has done,[b] file.length() would probably give you the result .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic