Member Avatar for amogh.max

here is my code and i have tokenized the data in my .txt file.I want to insert them into a database.

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.StringTokenizer;

public class test1 {

    public static void main(String[] args) {

        BufferedReader br = null;

        try {

            String sCurrentLine;

            br = new BufferedReader(new FileReader("D:\\Warface Launcher\\eclipse is fk\\something\\src\\2.txt"));

            while ((sCurrentLine = br.readLine()) != null) {
                System.out.println(sCurrentLine);
                StringTokenizer defaultTokenizer = new StringTokenizer(sCurrentLine);
                while (defaultTokenizer.hasMoreTokens())
                {
                    System.out.println(defaultTokenizer.nextToken());
                }
            }

        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (br != null)br.close();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }

    }
}

my current Output:`23 30 40 320 49 290 04 30 48 73 83
23
30
40
320
49
290
04
30
48
73
83

  1. You don't save the tokens extracted.
  2. I don't see where you identify what database columns each item is associated with.
  3. I see no associated database, connections to it, etc.

You have more work to do before we can help you. Or at least before I can help you.

Also: don't use StringTokenizer. It's only maintained not to break 'older' code. To quote it's api:

StringTokenizer is a legacy class that is retained for compatibility reasons although its use is discouraged in new code. It is recommended that anyone seeking this functionality use the split method of String or the java.util.regex package instead.

Honestly now... if we are to give appropriate help then we need to know did you write that yourself from scratch, or did you copy from some web site? What's strange is that you have code written for an old version of Java.

Member Avatar for amogh.max

its a mashup of code i found from web places and i seemed to understand that code (didnt know that it was legacy code).anyway i solved the problem.one more thing is ,this project i'm working on dosen't need network access ,everyhing is done locally.Right now my code can
1.read a text file and tokenize the dataand display it in the console.
2.it will transfer the tokenized data into ms access dynamically along with a time stamp.

OK
Next you need to store that tokenised data in some variables or data structure ready to write it to the database. The best choice for that depends on what the database record structure will be. So what is the database structure - do those numbers all go into one record, or is it one record per number,or something else?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.