Dear Daniweb Members,
First of all sorry my english writing.
I installed JavaJDK 7u13 with NetBeans 7.2.1 and 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 Method)
    at java.lang.ClassLoader.loadClass(
    at sun.misc.Launcher$AppClassLoader.loadClass(
    at java.lang.ClassLoader.loadClass(
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(
    at seconexample.SeconeXample.main(
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-;
**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-;

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 :

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>");

    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) )";
    conn = DriverManager.getConnection(connectionURL);
    Statement stmt = conn.createStatement();
    PreparedStatement psInsert = conn.prepareStatement("insert into employee values (1,'Erica')");
    psInsert.setString(1, args[0]);
    psInsert.setString(2, args[1]);
    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 ( {
      System.out.println(++num + ": Id: " + rs.getString(1) + "\n Name"+ rs.getString(2));

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

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, learning, and sharing knowledge.