aspose file tools*
The moose likes JSP and the fly likes Upload a csv file on JSP, validate the content and then perform query. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Upload a csv file on JSP, validate the content and then perform query." Watch "Upload a csv file on JSP, validate the content and then perform query." New topic
Author

Upload a csv file on JSP, validate the content and then perform query.

Nitish Agrawal
Greenhorn

Joined: Feb 11, 2008
Posts: 21
Hi All,

Query - how to upload a csv format file on JSP page and validate the content of that csv file. And perform Search on a particular field of that csv file?
( for example - There is an UPLOAD button on JSP, on click of that button I should be able to upload the excel/csv file and on click of a SEARCH button, my query will fetch one field from that uploaded excel/csv and perform search. something similar to it ).
My question may seems bit vague to someone but I know I will definitely get some idea over here. Thanks in advance..!!
William P O'Sullivan
Ranch Hand

Joined: Mar 28, 2012
Posts: 859

Yes it is vague.

The csv can be loaded field per column into a db table and then use standard sql or whatever.

If no db, then maintain the csv in session (could be really big though) and iterate through it using scanner or tokenize, split etc.

WP
Nitish Agrawal
Greenhorn

Joined: Feb 11, 2008
Posts: 21
Yep, I know but it can be narrow down by experts. That's why I am here.
I am using DB and I don't want to maintain that in session. So you mean to say I have to save that field (of CSV) in a DB table and then only I can perform search query.
Piyush Mangal
Ranch Hand

Joined: Jan 22, 2007
Posts: 196
Nitin Agrawal wrote:So you mean to say I have to save that field (of CSV) in a DB table and then only I can perform search query.


You need to save all the fields and records in your uploaded csv to database and then perform a search on column corresponding to the field from csv file.
Nitish Agrawal
Greenhorn

Joined: Feb 11, 2008
Posts: 21
Can somebody please share any example (code snippets) something similar to it. It will be of great help.
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1026
Nope, not likely. This place isn't a coding farm.
The point is that you try it yourself, and present problems/issues here.

As has been pointed out, your problem is very ill defined.
Breaking it into steps

- Upload a csv file : should be straightforward. Use any of the standard file upload libraries - eg apache commons fileupload
- "validate" the csv file - what is it we are validating?
- validate that it is in csv format?
- validate the data in some way? Not enough information.
- "search" the csv.
How do you define a query? What syntax? What parameters? How does the user do it?
How do you define which columns are searchable?
How do you even define what the columns to search are? A "header" row in the CSV?


Once you have defined your problem better, you will be able to take the steps to implement yourself.
William P O'Sullivan
Ranch Hand

Joined: Mar 28, 2012
Posts: 859

Click on Upload = 1 request

Click on Search = 1 request

Between these two, you have to save/persist/maintain the searchable data.

If you honestly do not know how to search(cough select) through a database then you need to do some research.


My advice, Get the csv post-validation, whatever into a database table(s). Once there, write some sql queries
using your favorite tool and work backwards.

WP
Nitish Agrawal
Greenhorn

Joined: Feb 11, 2008
Posts: 21
Hi Stefan, I had mentioned that I want to validate the content of csv file.
Better explanation would be something like -
for ex.
Employee Id is the only field in csv file and i want to perform some search on only VALID id's. (Valid id can be only of 6 digits)
And to be very frank, I am not pretty sure where and how to validate the csv data?

Step 1 : Upload csv
Step 2 : validating the data(one field only) of csv
Step 3 : finally Search on that 1 field of csv(query)


Thanks William, its such a nice explanation. But as such I don't have to maintain any searchable data except the csv content and post that I have to do a SEARCH.
Its great, if someone can provide the FLOW that - on uploading I have to call an ACTION CLASS and then do I have to load that csv content into DB or where (nt sure)?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Upload a csv file on JSP, validate the content and then perform query.