Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: open multiple text file to input to mysql

  1. #1
    Member
    Join Date
    Oct 2011
    Posts
    35
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default open multiple text file to input to mysql

    Hello everyone,
    I am trying to figure a way to open multiple text files to "write" to seperate tables in a mysql db. When I try to open another FileInputStream my ide, (NetBeans) doesn't like it and I can't say I don't blame it. I am unfamiliar with how to do this. I have checked over my texts and searched and cannot seem to find the right thing. Here is what I have;
    FileInputStream fstream = new FileInputStream("roster");
              DataInputStream in = new DataInputStream(fstream);
              BufferedReader br = new BufferedReader(new InputStreamReader(in));
              String strLine;
              ArrayList list = new ArrayList();
              while ((strLine = br.readLine()) != null) {
                  list.add(strLine);
              }
              Iterator itr;
              for (itr = list.iterator(); itr.hasNext();) {
                  String str = itr.next().toString();
                  String delims = "[ : L ]+";
                  String[] splitSt = str.split(delims);
                  String id = "", firstName = "", lastName = "";
                  for (int i = 0; i < splitSt.length; i++) {
                      id = splitSt[0];
                      firstName = splitSt[1];
                      lastName = splitSt[2];
     
                  }
     
                  int k = stmt.executeUpdate("insert into roster_cs368(id, firstName,"
                          + "lastName) values('"+ id +"', '"+ firstName +"',"
                          + " '"+ lastName +"')");
                  fstream.close();
              }

    This portion does work. How can I go about using FileInputSteam more than once? Some examples would really help.
    Thank You everyone.


  2. #2
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 139 Times in 134 Posts

    Default Re: open multiple text file to input to mysql

    What do you mean by "doesn't like it"? Are you getting compiler error messages? If so, this has nothing to do with the IDE and all to do with Java not liking things. You will want to show us any and all error messages and indicate the lines that are causing your errors.

  3. #3
    Member
    Join Date
    Oct 2011
    Posts
    35
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: open multiple text file to input to mysql

    Quote Originally Posted by curmudgeon View Post
    What do you mean by "doesn't like it"? Are you getting compiler error messages? If so, this has nothing to do with the IDE and all to do with Java not liking things. You will want to show us any and all error messages and indicate the lines that are causing your errors.
    Figured it out, thanks.

Similar Threads

  1. Having trouble splitting a text file into multiple arrays.
    By orbin in forum What's Wrong With My Code?
    Replies: 21
    Last Post: June 19th, 2012, 05:27 PM
  2. Replies: 6
    Last Post: December 9th, 2011, 04:53 PM
  3. probleming writing multiple items to text file
    By gskimmel in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 9th, 2011, 08:41 PM
  4. Create Multiple Arrays from a text file
    By chris11kgf in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: February 11th, 2011, 12:40 AM
  5. Open Text file
    By java_kiddy in forum File I/O & Other I/O Streams
    Replies: 7
    Last Post: October 5th, 2010, 02:52 AM