Dear Daniweb Members,
First of all sorry my english writing.
I installed JavaJDK 7u13 with NetBeans 7.2.1 and db-derby-10.5.3.0-bin.zip on a fresh OS. Then i set the environment variables according to their relative paths as seen below. By using ij the test database and the test table created, records inserted and displayed by using select. In command line and also in NetBeans IDE the HelloWorld console app run successfully. So far everything was fine. But when i try to make a connection inside NetBeans by using the code below i got the following exception. It prevents the application run correctly.

Any help will be gratefully appreciated.

Exception in thread "main" java.lang.ClassNotFoundException: org.apache.derby.jdbc.EmbeddedDriver
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:188)
    at seconexample.SeconeXample.main(SeconeXample.java:26)
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)**

***********************************************************************************
The environment variables settings :
**JAVA_HOME** = C:\Program Files\Java\jdk1.7.0_13 ;
**DERBY_HOME** = C:\Apache\db-derby-10.5.3.0-bin;
**CLASSPATH ** = %DERBY_INSTALL%\lib\derby.jar;%DERBY_INSTALL%\lib\derbytools.jar;
**Path** = %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\Java\jdk1.7.0_13\bin;
**DERBY_INSTALL** = C:\Apache\db-derby-10.5.3.0-bin;

Recommended Answers

All 3 Replies

It is saying that it can't find the class org.apache.derby.jdbc.EmbeddedDriver. I think you need to add the appropriate directory to your CLASSPATH variable. I see that you set DERBY_HOME to CLASSPATH, but I think that you are not going far enough.

I see that you set DERBY_HOME to CLASSPATH, but I think that you are not going far enough.

Hi rubberman. First of all thanks for your interest in the issue. I added "derby.jar" to NetBeans project. Then the output changes :

run:
Usage: java JavaDBDemo <Name> <Address>
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)

But it is not the completely expected result. Any idea ??

package seconexample;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;

public class SeconeXample {
  static Connection conn;
  public static void main(String[] args) throws Exception {
    if (args.length != 2) {
      System.out.println("Usage: java JavaDBDemo <id> <Name>");
      System.exit(1);
    }

    String driver = "org.apache.derby.jdbc.EmbeddedDriver";
    String dbName = "database10";
    String connectionURL = "jdbc:derby:" + dbName + ";create=true";
    String createString = "CREATE TABLE employee (id INT,empname VARCHAR(40) )";
    Class.forName(driver);
    conn = DriverManager.getConnection(connectionURL);
    Statement stmt = conn.createStatement();
    stmt.executeUpdate(createString);
    PreparedStatement psInsert = conn.prepareStatement("insert into employee values (1,'Erica')");
    psInsert.setString(1, args[0]);
    psInsert.setString(2, args[1]);
    psInsert.executeUpdate();
    Statement stmt2 = conn.createStatement();
    ResultSet rs = stmt2.executeQuery("select * from employee");
    System.out.println("Employee id and name presented in your table\n\n");
    int num = 0;
    while (rs.next()) {
    // DATABASE OUTPUT :
      System.out.println(++num + ": Id: " + rs.getString(1) + "\n Name"+ rs.getString(2));
    }
    rs.close();
  }
}

Thanks in advance.

hai smurfy

i think you need to pass user details for getting Connection object for accessing Underlying database

but i couldn't find the user details in your connection string url code

what i mean is while creating connection object we need to pass the user details of the database for access (in otherwords need access permisions)

so your connection string should be like as follows

String dbURL = "jdbc:derby://host_name:port_number/database_name;create=true;user=me;password=mine";

then pass that connection string url to the getConnection(dbURL) method (as you done previously)

thats it

i think that might be the problem in your code

please go through the following URL it gives brief idea on how to connect Derby Database clearly

http://db.apache.org/derby/integrate/plugin_help/derby_app.html

if you have any doubts in my clarification

let me know the status

happy coding

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.