0

I am using netbeans 12 with jdk 17. On building and running the following code, I get this error and no output is shown:

 java.lang.ClassNotFoundException: org.apache.derby.jdbc.ClientDriver at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520) at java.base/java.lang.Class.forName0(Native Method) at java.base/java.lang.Class.forName(Class.java:375) at bookclass.Bookclass.main(Bookclass.java:114) BUILD SUCCESSFUL (total time: 0 seconds) 

I have added all the jar files namely derby.jar, derbyshared.jar, derbyclient.jar, etc.

Code:

package bookclass; import java.sql.*; import java.util.*; class books { void insert() { try { Scanner in = new Scanner(System.in); Connection con = DriverManager.getConnection("jdbc:derby://localhost:1527/library"); Statement st = con.createStatement(); String s = "insert into bookstb values(" + id + ", '" + t + "', '" + p + "', '" + a + "', " + c + ", " + pr + ")"; int x = st.executeUpdate(s); System.out.println("No. of rows inserted: " + x); st.close(); con.close(); } catch (Exception e) { System.out.println(e.getMessage()); } } } public class Bookclass { public static void main(String[] args) { // TODO code application logic here try { Scanner in = new Scanner(System.in); Class.forName("org.apache.derby.jdbc.ClientDriver"); int ch; do { System.out.println("1.Insert 2.Update 3.Delete 4.Display 5.Exit\nEnter your choice:"); ch = in.nextInt(); books b = new books(); switch (ch) { case 1: b.insert(); break; case 2: b.update(); break; case 3: b.delete(); break; case 4: b.display(); break; case 5: System.exit(0); break; } } while (ch != 5); } catch (Exception e) { //System.out.println(e.getMessage()); e.printStackTrace(); } } } 

I have tried all the possible solutions available but none solve my issue.

9
  • 2
    You miss the jar containing class org.apache.derby.jdbc.ClientDriver in your class path Commented Sep 2, 2022 at 6:42
  • @jens does derbyclient.jar not contain it? Commented Sep 2, 2022 at 6:48
  • It should contains the class. But it is in your classpath while running your application Commented Sep 2, 2022 at 6:53
  • BTW: Take care of java naming conventions. Class names should start with upper case character Commented Sep 2, 2022 at 6:54
  • @jens how do I add a class to a jar file? Commented Sep 2, 2022 at 7:02

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.