Reputation: 529
Java Derby does not find a database even with "create=true" sentence.
The code is following:
public class Main{
public static void main(String[] args) {
try {
DriverManager.getConnection("jdbc:derby:javaDb;create=true");
} catch (SQLException e){
e.printStackTrace();
}
}
In CMD, from libs folder:
java -jar derbyrun.jar ij version ij 10.15 connect 'jdbc:derby:javaDb'; ERROR XJ004: Database 'javaDb' not found. show connections No connection available.
Upvotes: 0
Views: 263
Reputation: 21910
If I have interpreted your question correctly...
Quick Answer
(a) Run the ij
start-up command in the same location where your Java program created the new database (see below).
or
(b) Create the DB using ij
at the same time as you connect to it (also see below).
More Notes
When you create a new Derby DB using the Java code in your question, that will create the DB in the root folder of where the code (the Java project) was executed.
Look for a javaDb
folder there, containing the Derby database files.
But when you try to connect to that database at the ij>
command prompt, after running this:
java -jar derbyrun.jar ij
...and then using connect 'jdbc:derby:javaDb';
you are telling ij
that the DB is in the lib
directory of the Derby installation folder.
Those are probably two different locations - hence you get your "not found" error.
You can locate and copy the javaDb
folder from where it was created (your Java app) to the Derby installation's lib
folder. But probably not a good idea. You should keep the lib
folder clean.
Alternatively...
You can execute the java -jar derbyrun.jar ij
command from the parent folder of where the javaDb
folder is located (i.e. from your Java project root folder:
java -jar %DERBY_HOME%\lib\derbyrun.jar ij
(I am assuming that by "CMD" you mean a Windows command prompt.)
If DERBY_HOME
is not defined, then just use the full path to the Derby lib
folder.
Then, at the ij>
prompt, retry your connection command:
connect 'jdbc:derby:javaDb';
So, for example, for me, the Java command is this:
java -jar C:\derbydb\db-derby-10.16.1.1-bin\lib\derbyrun.jar ij
And I run the above command from where my Java project is located:
C:\Users\me\Documents\JavaDerbyDemo
Use ij
For DB Creation
What you maybe want to do instead of all of the above is to use ij
to actually create the DB as you first try to connect to it in ij
:
connect 'jdbc:derby:javaDbTwo;create=true';
That will create a javaDbTwo
folder (containing your new, empty Derby DB) in the same location where you run the command.
Upvotes: 2