• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 672
  • Last Modified:

Java: derby embedded driver test ok; yet test class fails... driver not found, any ideas why?

Hello Experts,

I just installed Derby and confirmed config... logs below:

C:\Users\Moe>cd\

C:\>echo %CLASSPATH%
C:\JAVA\derby\db-derby-10.9.1.0-bin\lib\derby.jar;C:\JAVA\derby\db-derby-10.9.1.
0-bin\lib\derbytools.jar;C:\JAVA\derby\db-derby-10.9.1.0-bin\lib\derbyclient.jar
;C:\JAVA\derby\db-derby-10.9.1.0-bin\lib\derbynet.jar;.

C:\>echo %DERBY_INSTALL%
C:\JAVA\derby\db-derby-10.9.1.0-bin

C:\>java org.apache.derby.tools.sysinfo
------------------ Java Information ------------------
Java Version:    1.7.0_04
Java Vendor:     Oracle Corporation
Java home:       C:\Program Files\Java\jre7
Java classpath:  C:\JAVA\derby\db-derby-10.9.1.0-bin\lib\derby.jar;C:\JAVA\derby
\db-derby-10.9.1.0-bin\lib\derbytools.jar;C:\JAVA\derby\db-derby-10.9.1.0-bin\li
b\derbyclient.jar;C:\JAVA\derby\db-derby-10.9.1.0-bin\lib\derbynet.jar;.
OS name:         Windows 7
OS architecture: amd64
OS version:      6.1
Java user name:  Moe
Java user home:  C:\Users\Moe
Java user dir:   C:\
java.specification.name: Java Platform API Specification
java.specification.version: 1.7
java.runtime.version: 1.7.0_04-b22
--------- Derby Information --------
[C:\JAVA\derby\db-derby-10.9.1.0-bin\lib\derby.jar] 10.9.1.0 - (1344872)
[C:\JAVA\derby\db-derby-10.9.1.0-bin\lib\derbytools.jar] 10.9.1.0 - (1344872)
[C:\JAVA\derby\db-derby-10.9.1.0-bin\lib\derbynet.jar] 10.9.1.0 - (1344872)
[C:\JAVA\derby\db-derby-10.9.1.0-bin\lib\derbyclient.jar] 10.9.1.0 - (1344872)
------------------------------------------------------
----------------- Locale Information -----------------
Current Locale :  [English/United States [en_US]]
Found support for locale: [cs]
         version: 10.9.1.0 - (1344872)
Found support for locale: [de_DE]
         version: 10.9.1.0 - (1344872)
Found support for locale: [es]
         version: 10.9.1.0 - (1344872)
Found support for locale: [fr]
         version: 10.9.1.0 - (1344872)
Found support for locale: [hu]
         version: 10.9.1.0 - (1344872)
Found support for locale: [it]
         version: 10.9.1.0 - (1344872)
Found support for locale: [ja_JP]
         version: 10.9.1.0 - (1344872)
Found support for locale: [ko_KR]
         version: 10.9.1.0 - (1344872)
Found support for locale: [pl]
         version: 10.9.1.0 - (1344872)
Found support for locale: [pt_BR]
         version: 10.9.1.0 - (1344872)
Found support for locale: [ru]
         version: 10.9.1.0 - (1344872)
Found support for locale: [zh_CN]
         version: 10.9.1.0 - (1344872)
Found support for locale: [zh_TW]
         version: 10.9.1.0 - (1344872)
------------------------------------------------------

C:\>cd JAVA\derby\db-derby-10.9.1.0-bin\demo\programs\simple

C:\JAVA\derby\db-derby-10.9.1.0-bin\demo\programs\simple>java SimpleApp
SimpleApp starting in embedded mode
Loaded the appropriate driver
Connected to and created database derbyDB
Created table location
Inserted 1956 Webster
Inserted 1910 Union
Updated 1956 Webster to 180 Grand
Updated 180 Grand to 300 Lakeshore
Verified the rows
Dropped table location
Committed the transaction
Derby shut down normally
SimpleApp finished

Open in new window


via CMD, I am able to connect and create a test table.. logs below:

C:\JAVA\sip>ij
ij version 10.9
ij> connect 'jdbc:derby:C:\JAVA\sip\firstdb;create=true';
ij> CREATE TABLE FIRSTTABE(ID INT PRIMARY KEY, NAME VARCHAR(12));
0 rows inserted/updated/deleted
ij> INSERT INTO FIRSTTABE VALUES
> (10,'TEN'),
> (20,'TWENTY'),
> (30,'THIRTY');
3 rows inserted/updated/deleted
ij> SELECT * FROM FIRSTTABE
> ;
ID         |NAME
------------------------
10         |TEN
20         |TWENTY
30         |THIRTY

3 rows selected
ij> exit;
C:\JAVA\sip>

Open in new window


however, when I tried to run test class below, I get
java.lang.ClassNotFoundException: org.apache.derby.jdbc.EmbeddedDriver

this is the class:

static Connection conn;

//main

		String driver = "org.apache.derby.jdbc.EmbeddedDriver";// Derby Embedded

		String connectionURL  = "jdbc:derby:C:\\JAVA\\sip\\firstdb";
		String createString = "CREATE TABLE Employee (NAME VARCHAR(32) NOT NULL, ADDRESS VARCHAR(50) NOT NULL)";
		try {
			Class.forName(driver);
		} catch (java.lang.ClassNotFoundException e) {
			e.printStackTrace();
		}
		try {
			conn = DriverManager.getConnection(connectionURL);
			Statement stmt = conn.createStatement();
			stmt.executeUpdate(createString);

			PreparedStatement psInsert = conn
					.prepareStatement("insert into Employee values (?,?)");

			psInsert.setString(1, args[0]);
			psInsert.setString(2, args[1]);

			psInsert.executeUpdate();

			Statement stmt2 = conn.createStatement();
			ResultSet rs = stmt2.executeQuery("select * from Employee");
			int num = 0;
			while (rs.next()) {
				System.out.println(++num + ": Name: " + rs.getString(1)
						+ "\n Address" + rs.getString(2));
			}
			rs.close();
		} catch (Exception e) {
			e.printStackTrace();
		}

Open in new window


any ideas what I am doing wrong?

In advance, thank you for your help...

Regards,
0
epifanio67
Asked:
epifanio67
  • 2
1 Solution
 
CEHJCommented:
Copy the loadDriver from SimpleApp.java and use that.

Are you compiling and running your own code at the command line?
0
 
epifanio67Author Commented:
Thanks for your help CEHJ...

I needed to add derby jars to the project....

Regards,
0
 
CEHJCommented:
:)
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now