Loading contents of a *.CSV file into a database

I have a *.csv file whose contents I want to add into a database. How can I possibly do this using Javascript or JSP?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

From JSP these are summary steps:

1- using java.io, read the CSV line by Line, each line into a String
2- if it is comma delimited, for each line use:

String[] fields = String.split("[,]');

u will get what represents the Single Record fields in the fields String Array

3- For each line use JDBC to insert into dataase, by a SQL statment like this:

insert into mytable values( {ur fields} );

ALL Points to petmagdy, but I feel the urge to elaborate a bit:

>"1- using java.io, read the CSV line by Line, each line into a String"
See here: http://www.javaalmanac.com/egs/java.io/ReadLinesFromFile.html
You simply append the text to a String.

>"2- if it is comma delimited"
Try using the StringTokenizer class (from the java.util) package:

        StringTokenizer st = new StringTokenizer ( stringToTokenize, "," );

        String[] fields = new String [ st.countTokens()];
        for ( int i=0; i<st.countTokens(); i++ )
            fields[i] = st.nextToken();

>"For each line use JDBC to insert into dataase"

This may help:

Good luck with it ;-)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DrWarezz, thanks your good value add and elaboration, deserves all the points thanks
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

:-) No, I insist.  I honestly would feel like a 'point-theif' if I were to get the points, as you've answered the Q, I just elaborated a bit, because I felt that the author clearly wasn't TOO confident on how to do this. :-)

So, author; no matter what petmagdy says, give him the points  :-)

no "point-theif" u gived the answer more intension than me and provided value add, author best solution to split

but wait a minute where is the author? seems not interested any more ;-)
more attension i mean, miss tepo, hhhhhhhhhh LOOOLLLLLLLLLLL
lol -- it makes sense either way ;-)
Okay.. thanks, VbMonk  :-)

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.