Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

output to excel

 
sai rama krishna
Ranch Hand
Posts: 432
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



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
Posts: 432
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 432
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You urgently need to read up on what SQL injection is, and what to do to prevent it.
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic