Hi ! I have developed a Java application using Derby Database. The application jar file is successfully running on Windows but on Mac it gives and exception as following:

  ClassNotFoundException: org.apache.derby.jdbc.EmbeddedDriver

I am pasting code for database Connection which I wrote.

         String dbdriver = "org.apache.derby.jdbc.EmbeddedDriver";
         Class.forName(dbdriver).newInstance();
         con = DriverManager.getConnection("jdbc:derby:C:\\4DSOFTECHDB; create = true"); 

Note: This exception occurs only on Mac OS.

I have no experience with Java or Derby. But your code seems to connect to a database whose files are stored at a path on the C:\ drive. That type of file system convention doesn’t exist on macOS, which is Unix-based. Instead, try replacing the path with something like /home/username/softechdb.

Dani is right. But to specify a location within your home folder in MacOS use the Tilda, eg ~/Documents/softechdb

commented: I know I am replying very late, Yes it was the Path format error. But there is only one problem +3

Thanks Dani and James. I tried the Path as you told, but I am facing same error. I tried to create a simple txt file and it created successfully by using your path guidelines. But the problem is remain there regarding the DB. It seems like that there is a problem regarding to DB driver class. But I could not find it. On windows it is running successfully.

Derby is not included in current JDK distributions, you need to download it separately and add the jars to your classpoath or project libraries.
Maybe your Windows JDK is old (pre JDK 9?) or maybe it was downloaded at some time in the past and is still there?
Ps The old ClassForName thing has been obsolete since Java 6. It's embarrassing how many web tutorials still show it.
All you need is getConnection with a suitable URL, eg

        var dbURL = "jdbc:derby:/users/james/derbyTest;create=true";
        Connection conn = DriverManager.getConnection(dbURL);

(Yes, I just tested that under Catalina on a M1 Mac)

commented: I am using Java 7. I am trying to add Class Path on my clients PC using terminal. Terminal is saying : access denied +3

Do you mean the Java 7 that was released in 2011? Last public updates 2015? With all its unfixed bugs and security vulnerabilities? The 7 that's so old it doesn't even have lambdas?
Unless someone is forcing you to use that at gunpoint you should stop doing anything else until you have updated to Java 17 (the current long term support version).

commented: +1 +16
commented: I agree with you . But the problem is I had written the code of that specific application in java 7. Will this app run flawlessly with Java 17? +0

Code written for J7 should run ok on J17. There have only been very few changes in Java that create backwards compatibility problems. (Too few IMHO. It's a shame how great improvements like generics were handicapped by the constraints of remaining 100% compatible.)
It only takes a few minutes to download J17 and try it.

commented: not quite. A lot of functionality was removed in J11, like the entire XML handling. -4

Derby was included in Java7, it isn't in Java17 as it was removed with the release of Java9.
https://stackoverflow.com/questions/53911999/where-is-the-derby-jar-file-within-my-java-11-installation-on-mac
Java11 saw a whole bucket list of stuff removed as well, and some more pruning has been going on since.
Mostly these are features that were duplicated from Java EE or are simply almost never used any longer (like CORBA).
https://www.oracle.com/java/technologies/javase/11-relnote-issues.html
They're also slowly (and finally) removing deprecated functionality, especially where there are security implications.
http://cr.openjdk.java.net/~iris/se/11/latestSpec/api/deprecated-list.html

Together with your JDBC URL being incorrect that's why your application isn't working on your Mac, which no doubt comes with a version of Java way newer than 7 installed (if you're still using 7 on your computers, it's past time to replace it as it's no longer supported and has some known security vulnerabilities among other things, and with all the language changes since you shouldn't be writing for it anyway unless you're maintaining a very old legacy system where for some obscure reason the machines it is running on can't use a later JVM).

One tiny point… XML is alive and kicking in Java 17. It’s just the EE related JAX stuff that was removed.

First of All sorry for very Late Reply. Actually My client was out of country for a few months , so the work was postponed. No he came back.

Yes James You were right. It was the path Format error on Mac. But one problem is remaining and I am stuck on it. I wrote the path in the same way as you told. The application is running on Mac BigSur(installed on Virtual Box)perfectly but gives following exception on Physical Mac(having Mac OS BigSur installed):
java.lang.ClassNotFoundException:org.apache.derby.jdbc.EmbeddedDriver

I am pasting the code I wrote for connection:

String dbDriver = "org.apache.derby.jdbc.EmbeddedDriver";
class.ForName(dbDriver).newInstance;
con = DriverManager.getConnection("jdbc:derby:/users/daniyalumar/4DSoftectDB;create = true");

Code is working on Virtual MacOS perfectly but gives and exception on Physical Mac.

First: you are still using Class.forName. It’s obsolete. See my previous post on the subject.
Second: looks like the Derby jars are not in the class path on the real machine.

commented: I removed the Class.forName method and it gave me Error: No suitable driver. +3

Do you mean the Java 7 that was released in 2011? Last public updates 2015? With all its unfixed bugs and security vulnerabilities? The 7 that's so old it doesn't even have lambdas?

commented: If you are going to post then post something original. -3
commented: Yes I mean Java 7, because it has derby.jar already in it and no need to install Derby explicitly. My Application works on Windows OS perfectly +3

MacOS is not allowing me to set Derby_Home environment Variable also. it gives zsh:permission denied error

I used following command on terminal:

export DERBY_HOME=$(/Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home/db)

Try it without the $(

export DERBY_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home/db

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.