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?

Improve company productivity with a Business Account.Sign Up

DrWarezzConnect With a Mentor Commented:
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 ;-)
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} );

DrWarezz, thanks your good value add and elaboration, deserves all the points thanks
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

:-) 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  :-)

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.