[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Loading contents of a *.CSV file into a database

Posted on 2004-10-30
8
Medium Priority
?
163 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

With the evolution of technology, we have finally reached a point where it is possible to have home automation features like having your thermostat turn up and door lock itself when you leave, as well as a complete home security system. This is a st…
Geo-targeting is the practice of distributing content based on a person’s location, as best as you can determine it. Let’s look at some ways you could successfully use this tactic. The following tips and case studies could lead to meaningful results.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

649 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