• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

output to excel

 
Ranch Hand
Posts: 930
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 930
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 930
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic