aspose file tools*
The moose likes Beginning Java and the fly likes output to excel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "output to excel" Watch "output to excel" New topic
Author

output to excel

sai rama krishna
Ranch Hand

Joined: May 29, 2009
Posts: 269



I have above java application which reads from File.xls for username and password and checks againest the database if that username and password is exists or not. If it does not exist puts in missingList and printis to console that info. Instead of printing tp console i want it to send to excel. I have a program(from link http://sanjaal.com/java/105/java-file/writing-to-excel-file-using-apache-poi/) that is writing to excel as follows





Can you please advise how do I integrate above 2 programs to get desired missinList output into an excel format
Any ideas, suggestions, sample code, links, source code highly appreciated. Thanks in advance
sai rama krishna
Ranch Hand

Joined: May 29, 2009
Posts: 269


As shown in above program I am trying to loop through the Hashmap and fill in the cells. But not working some reason. Please advise
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18657
    
    8



This if-condition will never be true, because the executeQuery() method never returns null. (The API documentation specifically says that.)

So none of the code controlled by that if-condition will ever be executed -- and that's the code you are asking about, isn't it? Although you could perfectly well have found that out by doing some simple debugging.

But there's plenty more in that code to be concerned about. You have a very strange SQL statement, followed by some code which (if executed) would throw exceptions, and anyway assigns its results to local variables which can never be used. And you don't have any code which writes your Excel document out to a file, which appears to be one of your main requirements.
sai rama krishna
Ranch Hand

Joined: May 29, 2009
Posts: 269
Actually i modified my qiery as below

which is working fine

ResultSet rs1 = stmt.executeQuery("select * from login where username='"+username+"' and password='"+password+"'");

now I need to loop in throguh hashmap or arraylist to populate excel cells as explained in link

http://sanjaal.com/java/105/java-file/writing-to-excel-file-using-apache-poi/

Please advise

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42277
    
  64
You urgently need to read up on what SQL injection is, and what to do to prevent it.


Ping & DNS - my free Android networking tools app
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18657
    
    8

Okay, so now you have a better SQL statement. But where does the map, or list, come into the picture? Or alternatively, what does SQL have to do with it?

It appears you have found some code which writes out an Excel spreadsheet. You'll notice that part of that code is involved in filling in cells in the spreadsheet, and the rest is machinery which sets up the spreadsheet and writes it out. So your task is to take the filling-in-cells code and replace it by your code, which gets data from wherever it gets it from.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: output to excel