Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Loading contents of a *.CSV file into a database

Posted on 2004-10-30
8
Medium Priority
?
165 Views
Last Modified: 2010-04-01
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
0
Comment
Question by:VbMonk
  • 4
  • 4
8 Comments
 
LVL 13

Expert Comment

by:petmagdy
ID: 12453658
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
 
LVL 9

Accepted Solution

by:
DrWarezz earned 200 total points
ID: 12457475
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
 
LVL 13

Expert Comment

by:petmagdy
ID: 12457491
DrWarezz, thanks your good value add and elaboration, deserves all the points thanks
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 9

Expert Comment

by:DrWarezz
ID: 12457522
:-) 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
 
LVL 13

Expert Comment

by:petmagdy
ID: 12457538
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
 
LVL 13

Expert Comment

by:petmagdy
ID: 12457548
more attension i mean, miss tepo, hhhhhhhhhh LOOOLLLLLLLLLLL
0
 
LVL 9

Expert Comment

by:DrWarezz
ID: 12457551
lol -- it makes sense either way ;-)
0
 
LVL 9

Expert Comment

by:DrWarezz
ID: 12458127
Okay.. thanks, VbMonk  :-)

[r.D]
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A Case Study of using the Windows API to provide RS232 communications capability in Access without the use of Active-X controls.
Often, the users face difficulty in accessing Outlook 2016 PST files on Windows 10 computer. One of the reasons behind it is the improper functioning of MS Outlook when the user tries to open it. MS Outlook suddenly stops working, or it will not op…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question