Hello,
I have some questions about how to work with urls in java. Any help would much appreciated.

When I execute the following code from my app it executes just fine. But when I move my app to a different directory and change the url accordingly, it fails.

original code:
String url = "jdbc:mckoi:local://./db.conf";

modified code:
String url = "jdbc:mckoi:local://./mckoi1.0.3/db.conf";

Also, when I execute the a jar file from within same directory with the following command, it executes perfectly. But it fails if I try to run the jar from different directory because it fails to find the db.conf file. (the jar file and the db.conf are always in the same directory).

Original command:
java -jar mckoidb.jar -create "admin_user" "aupass00"

Modified command:
java -jar ./mckoi1.0.3/mckoidb.jar -create "admin_user" "aupass00"

What am I doing wrong? Am I supposed to treat relative url differently with Java?

Are you sure that you are on appropriate level from which give path is leading to mentioned files, or you in same directory as these files?

I am in /home/. the jar files and and db.conf is in /home/mckoi1.0.3/. My code runs if I run it from /home/mckoi1.0.03/ with String url = "jdbc:mckoi:local://./db.conf"; But it it does not run if I put my code in /home/ with String url = "jdbc:mckoi:local://./mckoi1.0.3/db.conf";

The jar command executes without error if its run from /home/mckoi1.0.03/ . But it does not run from /home. I am hoping that there are some trivial rules regarding urls that I don't know about.

Check permisions for your folder mckoi1.0.03 if they are setup properly (I asume you using Unix base system as you mentioned home directory).
Reconsider arrangement of path in your coding. If file and one and two are in same directory, file one need access to file two and you want to execet them from diferent directory. Then provide full path for execution for file one, but you do not need to do same for file two as it is called from same level.
If this doesn't help, I will have to ask you to provide parts of code to see what is going on...

I made mckoi1.0.03 fully executable.
The following is the code I am trying to execute:

import java.sql.*;

public class EmbeddedDatabaseDemo {

    public static void main(String[] args) {
   
    // Register the Mckoi JDBC Driver
    try {
        Class.forName("com.mckoi.JDBCDriver").newInstance();
    }
    catch (Exception e) {
        System.out.println(
        "Unable to register the JDBC Driver.\n" +
        "Make sure the JDBC driver is in the\n" +
        "classpath.\n" + e);
        System.exit(1);
    }

    // This URL specifies we are connecting with a local database
    // within the file system.  './db.conf' is the path of the
    // configuration file of the database to embed.
    String url = "jdbc:mckoi:local://./mckoi1.0.3/db.conf";

    // The username / password to connect under.
    String username = "admin_user";
    String password = "aupass00";

    // Make a connection with the local database.
    Connection connection;
    try {
        connection = DriverManager.getConnection(url, username, password);
    }
    catch (SQLException e) {
        System.out.println(
        "Unable to make a connection to the database.\n" +
        "The reason: " + e.getMessage());
        System.exit(1);
        return;
    }

    try {
   
        // .... Use 'connection' to talk to database ....


        // Close the connection when finished,
        connection.close();

    }
    catch (SQLException e) {
        System.out.println(
        "An error occured\n" +
        "The SQLException message is: " + e.getMessage());
        return;
    }

    }

}

The mckoi1.0.3 folder can be found here:
http://www.mckoi.com/database/ver/mckoi1.0.3.zip
It is a portable java database. Just initilize the database with the following command before running the code above:
java -jar mckoidb.jar -create "admin_user" "aupass00"

Thank you very much.

Ok, I think I know what is causing your issue. Check your db.conf file for the root_path property. If you left it set to the default 'jvm' then you need to change that to use "configuration" as below

# root_path - If this is set to 'jvm' then the root
#   path of all database files is the root path of the
#   JVM (Java virtual machine) running the database
#   engine.  If this property is set to 'configuration'
#   or if it is not present then the root path is the
#   path of this configuration file.
#   This property is useful if you are deploying a
#   database and need this configuration file to be the
#   root of the directory tree of the database files.

root_path=configuration
#root_path=jvm
commented: spot on! +11

I don't know how you figured it out but thank you. It is working now.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.