i want to Read DATA From A text file and save it in database and print the logs by using JAVA.?
PLSSSSS HELP....

i want to Read DATA From A text file and save it in database and print the logs by using JAVA.?
PLSSSSS HELP....

well i guess first you need to read in the text from the text file. Have a google on 'Read Text file in java' and there is your first piece of the problem done....

no it throwing no class def exception.........

no it throwing no class def exception.........

well could you post your code so far? Then i might be able to help but without seeing the code its hard for me.

and also, if you run it through the command line, the commands you used to compile/run your application might come in handy

and also, if you run it through the command line, the commands you used to compile/run your application might come in handy

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileNotFoundException;
import java.io.IOException;

public class FileRead {
    public static void main(String[] args) {
        File file = new File("myfile.txt");
        StringBuffer contents = new StringBuffer();
        BufferedReader reader = null;

        try {
            reader = new BufferedReader(new FileReader(file));
            String text = null;

            // repeat until all lines is read
            while ((text = reader.readLine()) != null) {
                contents.append(text)
                    .append(System.getProperty(
                        "line.separator"));
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (reader != null) {
                    reader.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        
        // show file contents here
        System.out.println(contents.toString());
    }
}

After compilation class file generated but when i running it ait shows exception

After compilation class file generated but when i running it ait shows exception

What does the full exception say? all runs fine on my netbeans

What does the full exception say? all runs fine on my netbeans

its showing error...

Exception in thread "main" java.lang.NoClassDefFoundError: FileRead


actually its my first day at company and a have to do this as its a first assignment...

Read DATA From A text file and save it in database and print the logs by using JAVA.?

so can u plss help....

its showing error...

Exception in thread "main" java.lang.NoClassDefFoundError: FileRead


actually its my first day at company and a have to do this as its a first assignment...

Read DATA From A text file and save it in database and print the logs by using JAVA.?

so can u plss help....

is the file which you source code is present in named 'FileRead.java'? -"As always the NoClassDefFoundError is caused due to classpath problems or missing jar files."

is the file which you source code is present in named 'FileRead.java'? -"As always the NoClassDefFoundError is caused due to classpath problems or missing jar files."

everything is fine file is there code is not having error but ...?

everything is fine file is there code is not having error but ...?

To be honest im not sure it works perfectly on my computer and all i changed was the main class name to match mine?

Uhm all i can suggest is create a new simple class that prints hello or something. if that compiles and runs fine then just copy and paste your code for the file reader into your new class which you know works, and then hopefully it will solve this error?

To be honest im not sure it works perfectly on my computer and all i changed was the main class name to match mine?

Uhm all i can suggest is create a new simple class that prints hello or something. if that compiles and runs fine then just copy and paste your code for the file reader into your new class which you know works, and then hopefully it will solve this error?

..

at net beans its working... okk but how to save it at database and print logs...

..

at net beans its working... okk but how to save it at database and print logs...

well, what kind of database i.e MS Access etc? and do you want to print logs from the database or a text file?

well, what kind of database i.e MS Access etc? and do you want to print logs from the database or a text file?

in mysql...
and logs should be in a text file as insertion successfull or failed...

in mysql...
and logs should be in a text file as insertion successfull or failed...

I cant help on the mysql side as i've only used Access, but i can tell you that another google search on 'write text to file java' will solve your last problem. and as for the mysql, you will have to wait until somebody who knows how mysql db and java works reads this thread.

Learn how to use the command prompt for your operating system. The "NoClassDefFoundError" indicates it can't find the classfile you just compiled, so you're in the wrong directory.
This can be solved either by changing to the right directory to launch the program or by changing the command line of the Java command to include the proper directory on its classpath or by modifying your system classpath to include that directory (the last is not recommended, but included just to be complete).

Also learn to always put your classes in packages, but that's secondary.

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.