0

I have embedded an Apache Derby database inside a JAR (it's the only thing located inside the jar). I'm trying to connect to that database with an executable JAR (the database jar would be inside the executable one). I'm able to successfully connect to it within my IDE, but not when I run the executable from the command line. I get and error saying it cannot find the database jar.

My code:

public static void queryDatabase() throws IOException {
        String connection = "jdbc:derby:jar:(src/main/resources/dbs.jar)employees";

        try (Connection conn = DriverManager.getConnection(connection)) {
            RowSetFactory factory = RowSetProvider.newFactory();
            CachedRowSet cachedRowSet = factory.createCachedRowSet();
            cachedRowSet.setCommand("select id,salary,filingStatus from employees");
            cachedRowSet.execute(conn);

            while (cachedRowSet.next()) {
                System.out.print(cachedRowSet.getString("id") + " ");
                System.out.print(cachedRowSet.getFloat("salary") + " ");
                System.out.println(cachedRowSet.getString("filingStatus"));
            }

        } catch (SQLException exception) {
            exception.printStackTrace();
        }

    }

I know once the executable JAR builds, the src/main/resources url will no longer be valid. Is there anyway I can get the executable jar to find the internal database jar when running outside of the IDE?

  • [*Setting up an embedded Derby database in a standalone Java application*](https://stackoverflow.com/q/4393385/642706) and [*How to embed database derby in jar file*](https://stackoverflow.com/q/30182333/642706) and [*Java Desktop Application with Embedded Database*](https://stackoverflow.com/q/13069195/642706) and [*How to embed database in javadb with my javafx standalone database application*](https://stackoverflow.com/q/22993589/642706) – Basil Bourque Oct 27 '21 at 20:43
  • I appreciate your response but those links didn't really help – kyleryan1291 Oct 27 '21 at 23:25

0 Answers0