0

I have run this program over and over, and got no error. But when I packaged it up into an executable it wouldn't run. So I deleted my derbyDB file to run from scratch and get a better sense of the error from intellij. It is saying there is no suitable driver for the derby connection. I have checked the product structure, the jar is in the right place, and the DERBY_HOME variable is still correct. Does anyone have any ideas

error message:

"C:\Program Files\Java\jdk1.8.0_131\bin\java" -Dfile.encoding=windows-1252 -jar C:\Users\A5S17\IdeaProjects\TestingProto\out\artifacts\TestingProto_jar\TestingProto.jar
java.sql.SQLException: No suitable driver found for jdbc:derby:myDB;create=true
    at java.sql.DriverManager.getConnection(DriverManager.java:689)
    at java.sql.DriverManager.getConnection(DriverManager.java:270)
    at sample.Controller.createConnection(Controller.java:826)
    at sample.Controller.initialize(Controller.java:693)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71)
    at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2566)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3214)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
    at sample.Main.start(Main.java:21)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
    at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
    at java.lang.Thread.run(Thread.java:748)
java.lang.NullPointerException
    at sample.Controller.initialize(Controller.java:694)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71)
    at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2566)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3214)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
    at sample.Main.start(Main.java:21)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
    at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
    at java.lang.Thread.run(Thread.java:748)

Line 826 is the call to the function below:

private static String dbURL = "jdbc:derby:myDB;create=true";
    public static void createConnection() {
            try{
                Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance();
                //below gets the connection specified earlier
                conn = DriverManager.getConnection(dbURL);
                System.out.println("DB Connection Created!");
            }
            catch(Exception e) {
                e.printStackTrace();
            }
        }

Line 826 is the line conn = DriverManager.getConnection(dbURL);

enter image description here

enter image description here

contents of the META-INF Manifest:

Manifest-Version: 1.0
Main-Class: sample.Main
dgelinas21
  • 641
  • 3
  • 9
  • 22
  • Is `derby.jar` in your `CLASSPATH`? – Bryan Pendleton Aug 04 '17 at 20:48
  • Please show the contents of `META-INF/MANIFEST.MF` of `TestingProto.jar`, by the looks of it you haven't specified the `Class-Path` entry. – Mark Rotteveel Aug 05 '17 at 08:25
  • @BryanPendleton it shows up as being in the classpath – dgelinas21 Aug 06 '17 at 01:24
  • @MarkRotteveel just added the contents, there's only 2 lines in the Manifest though – dgelinas21 Aug 06 '17 at 01:24
  • 1
    And that is likely the problem, if you use `-jar`, then the class path is specified in the manifest, and yours doesn't specify one – Mark Rotteveel Aug 06 '17 at 07:09
  • How do you create a jar artifact in IDE? Basically, you have 2 options, see https://stackoverflow.com/a/42200519/2000323 which use different approach of how to package dependencies. – Andrey Aug 06 '17 at 09:45
  • @Andrey I have included the jar in my artifact already, as they did in that example. It still does not work. I added a picture of my artifact details for further review in the question. – dgelinas21 Aug 07 '17 at 11:32
  • 1
    Then the driver class is loaded and as noted in another answers for this exception: https://stackoverflow.com/a/1911487/2000323 you have connection url wrong. E.g. for remote derby connection (which uses mentioned driver class) url should be "jdbc:derby://:". And for embedded driver (driver class "org.apache.derby.jdbc.EmbeddedDriver") the url is of form: "jdbc:derby:". – Andrey Aug 07 '17 at 14:02

0 Answers0