简体   繁体   中英

Connect Derby to java

I'm trying to connect to a database using Derby in Java (using NetBeans), bIt i keep getting this error when I try to create a new database:

An error occurred while crating the database java.lang.ClassNotFoundException; org.apache.derby.jdbc.ClientDriver.

I've tried using Derby 10.16.1.1 and Derby 10.14.2.1.

The error message you are seeing suggests that the class org.apache.derby.jdbc.ClientDriver is not being found by the class loader at runtime. This class is necessary for connecting to a Derby database. There are few possible causes:

  1. The Derby jdbc driver is not in the class path of your project or application.
  2. The version of jdbc driver jar file isn't correct version for the version of Derby you are using. Please, check versions.

There is a comprehensive derby documentation where you can find more info and step-by-step guide.


In order to add org.apache.derby.jdbc.ClientDriver to your class path you can do few things, depending on your development environment:

  1. If you're using an IDE like Netbeans, you can add the JAR file to the project's build path by IDE UI, for example, that thread explains how to do so.
  2. If you're building your project with a build tool like Maven or Gradle , you can add the JAR file as a dependency in your project's pom.xml file or build.gradle file. You can read more about that approach here and here
  3. If you're running your project from the command line, you can add the jar file to the classpath by specifying it as a command-line argument when running your project's main class. For example, if the jar file is located in /lib/derby-jdbc.jar , the command would be:
java -cp /lib/derby-jdbc.jar YourMainClass

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM