I'm using H2 (h2-1.2.136.jar) on a Mac (Snow Leopard). H2 works fine
(I've played around with it quite successfully).

Now I wrote a simple Java app to query a small H2 database (the
"menagerie" database below, adapted from the same MySQL database).

I'm using Oracle JDeveloper to write, compile, and run the
application. Everything seems to be doing fine except that I get an
exception when the app attempts to execute the SQL statement.

I'm showing below the app's code, and then the error I get when I run
the app in JDeveloper. I'm also showing the exception (a different
one) when I run the same app from a Terminal prompt.

App Code:

package jdbch2;

import java.sql.*;

public class JDBCH2app {
  public static void main(String args[]) {

    try {
      //Load JDBC driver
      Class.forName ("org.h2.Driver").newInstance();
    }
    catch (Exception e) {
      System.out.println("Can't find the H2 JDBC driver");
      return;
    }

    String url = "jdbc:h2:menagerie";
    String userName = "marcc";
    String password = "java1";
    Connection conn;

    try {
      //Connect to database
      conn = DriverManager.getConnection (url);
      System.out.println ("Database connection established
successfully");
      //Create a Statement object to create the SQL statement
      Statement stmt = conn.createStatement();
      //Execute SQL statement and get results in a ResultSet
      ResultSet rs = stmt.executeQuery("select name, species from
pet");
      //Iterate through result set printing the two values for each
row
      while (rs.next())
        System.out.println("Name = " + rs.getString("name") + "Species
= " + rs.getString("species"));
    }
    catch (SQLException e) {
      System.out.println("Connection failed: " + e.getMessage());
      return;
    }

  }
}

This is the error I get when I run the app in JDeveloper:

/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home/bin/
java -classpath /Users/marcc/jdeveloper/mywork/jdbcH2/.adf:/Users/
marcc/jdeveloper/mywork/jdbcH2/jdbc-h2/classes:/Users/marcc/Oracle/
Middleware/jdeveloper/jdev/lib/h2-1.2.136.jar -
Djavax.net.ssl.trustStore=/Users/marcc/Oracle/Middleware/wlserver_10.3/
server/lib/DemoTrust.jks jdbch2.JDBCH2app
Database connection established successfully
Connection failed: Table "PET" not found; SQL statement:
select name, species from pet [42102-136]
Process exited with exit code 0.

Now, if I run the very same app from a Terminal prompt, I get another
error, as follows:

/applications/h2/bin marcc$ java ~/desktop/JDBCH2app
Exception in thread "main" java.lang.NoClassDefFoundError: /Users/
marcc/desktop/JDBCH2app
Caused by:
java.lang.ClassNotFoundException: .Users.marcc.desktop.JDBCH2app
        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:248)

What am I doing wrong?

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/h2-database?hl=en.

Reply via email to