0
[COLOR="Red"]import java.sql.*;
public class test {

    public static void main(String args[]) {

        // Define the url for the sample database
        String url = "jdbc:derby://localhost:1527/test";
        Connection con;
        String createString;
        createString = "create table test " +
                "(NAME varchar(32), " + 
                "NUMBER int, " +
                "FEEs float " ;
        Statement stmt;

        try {
            // Load database driver. This is old method of loading
            // database driver.
            Class.forName("org.apache.derby.jdbc.ClientDriver");

        } catch(java.lang.ClassNotFoundException e) {
            System.err.print("ClassNotFoundException: ");
            System.err.println(e.getMessage());
        }

        try {
            // Create database connection
            //con = DriverManager.getConnection(url,"app", "app");
           con = DriverManager.getConnection(url, "app", "app");
            // Create a statement and execute it
            stmt = con.createStatement();
            stmt.executeUpdate(createString);

            // If there is no exception, the COFFEES table must be successfully created
            System.out.println("TEST table is successfully created");

            // Close statement and connection
            stmt.close();
            con.close();

        } catch(SQLException ex) {
            System.err.println("SQLException: " + ex.getMessage());
        }
    }
}[/COLOR]

I take new project in Netbeans. With the above coding, i am getting following error when i m trying to run the file test.java

[COLOR="Red"]Compiling 1 source file to C:\Documents and Settings\Administrator\JavaApplication2\build\classes
compile-single:
run-single:
java.lang.NoClassDefFoundError: javaapplication2/test
Exception in thread "main" 
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)[/COLOR]

PLEASE HELP ME TO SOLVE THE ERROR.

Edited by happygeek: fixed formatting

3
Contributors
3
Replies
4
Views
9 Years
Discussion Span
Last Post by pranavdv
0

Have you declared a package? Try running a simpler "Hello World" program, because the error you are getting doesn't have to do with the sql part. Are you getting the error when you compile or when you run?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.