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..!!
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.
Joined: Feb 11, 2008
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.
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.
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.
Joined: Feb 11, 2008
Hi Stefan, I had mentioned that I want to validate the content of csv file.
Better explanation would be something like -
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)?