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?

Monk
VbMonkAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
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:
http://www.devdaily.com/java/edu/pj/jdbc/jdbc0002/


Good luck with it ;-)
[r.D]
0
 
petmagdyCommented:
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} );

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

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

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

[r.D]
0
 
petmagdyCommented:
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 ;-)
0
 
petmagdyCommented:
more attension i mean, miss tepo, hhhhhhhhhh LOOOLLLLLLLLLLL
0
 
DrWarezzCommented:
lol -- it makes sense either way ;-)
0
 
DrWarezzCommented:
Okay.. thanks, VbMonk  :-)

[r.D]
0
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.