Reading Text File and Dumping Data into MS SQL Server Database

I want to create an interface that will allow me to choose a text file and have that data populate a database and then that information is shown in the interface.

Can someone just push me in the right direction Go slow I haven't programmed in Java in over 3 years.



Answer this question

Reading Text File and Dumping Data into MS SQL Server Database

  • Anagoge

    Hi Brewer, you have many approach to do so..but if you really want to import a text file into database you can do by make the text is just like csv (comma separated value), and each line become one record.

    Fisrt u read the file by using a method from File class, read line by line After that you can parse eachline by using split method in string class just like below example

    import System.Collections.*;

    public class SplitTest
    {
        public Arraylist get_Parse(String words)
        {


            ArrayList al = new ArrayList
            String split[] = words.Split(new char[] { ';'});

            for (int iCtr = 0; iCtr < split.get_Length(); iCtr++) {
                String s = (String)split.get_Item(iCtr);
                if (!(s.Trim().Equals(""))) {
                    al.add(s);
                }
            }
     return al;
        }
    }

    Save all the result using ArrayList and after that you can insert tha data from arraylist into database by using SqlDataReader

    Hope is help..

    BTW you can make more simple by using xml...:)



  • tyther

    Helps me out some and I appreciate the time, but I guess I needed Java 101 again cause I kinda understand the code.....I do understand the logic but I need a step by step tutorial....

     

     


  • Reading Text File and Dumping Data into MS SQL Server Database