Resolution

How to connect to a Derby DB and run different queries?

AuthorFullName__c
Maayan Amrani
articleNumber
000004223
ft:sourceType
Salesforce
FirstPublishedDate
2018-07-25T14:19:17Z
lastModifiedDate
2024-03-10T07:46:09Z
VersionNumber
10
In order to run queries against Derby DB, we need to first connect to the DB by running the derbyrun.jar file:
$ java -jar Path_To_derbyrun.jar ij
  1. First, download the derby jar. You can find a download list for the derby jar HERE. For example:

    $ wget https://<DOWNLOAD_LINK_SITE>/db-derby-10.14.2.0/db-derby-10.14.2.0-lib.tar.gz
    
  2. Then, place it in a convenient directory (i.e. /opt/apache) and unzip the file:
    • $ mv db-derby-10.14.2.0-lib.tar.gz /opt/apache/; cd /opt/apache
    • $ tar xvf db-derby-10.14.2.0-lib.tar.gz
  3. Locate the location of derbyrun.jar to start it.
    • $ find / -type f -name derbyrun.jar
  4. Switch to “artifactory” user
    • $ su artifactory
  5. Then use that location in the java command to start ij
    • $ java -jar /opt/apache/db-derby-10.14.2.0-lib/lib/derbyrun.jar ij

We expect to see the following output:

  • ij version 10.14
  • ij>
  1. Once there, we will run the following command in order to connect to the db.
    Artifactory needs to be stopped to connect to the Derby database as Derby allows only one connection at a time.
    • For Artifactory 6.X:
ij> connect 'jdbc:derby:/var/opt/jfrog/artifactory/data/derby;create=true';
  • For Artifactory 7.X:
ij> connect 'jdbc:derby:/var/opt/jfrog/artifactory/data/artifactory/derby;create=true';
  • Note that the highlighted portion on the above command is where the derby database is located in your Artifactory instance.
  1. From here we will be able to run queries. For instance, running a simple ‘select’:
    • ij> SELECT * FROM access_users;
    • ij> SELECT sha1 FROM binaries ORDER BY sha1 ASC;
  2. Finally, once you've completed performing the SQL queries, make sure you close the connection to the database so Artifactory can connect to it once it's started.
ij> disconnect all;