1

I want to make a working program written in Java on Mac available to a Windows user, but the connection fails on Windows with a strange error message indicating Windows is looking for the DB in C::\windows\system32. The SQLite DB is located in the same folder as the Java program:

Connection conn = DriverManager.getConnection("jdbc:sqlite:Databasess/Logic1.sqlite");

I've made a JAR and put it in a folder called Aurora, so it looks like this:

TeachingMachine
   Aurora.v2.jar
   Images
   Audio
   databases
      Logic1.sqlite
      Logic2.sqlite

Transfer the entire folder to another Mac and it works perfectly. Transfer the same folder to my HP running Windows10 and it immediately gives me an error that I had copied from my HP to my Mac:

JAVA.SQL ‘SQLEXCEPTION: path to ’databases/Logic1.sqlite’: C:\windows\system32:’databases’ does not exist

I've searched for pleas for help regarding windows\system32, and larger portions of the error message. I've found some people whose questions involved gremlins in their code for making a connection to SQLite or other databases, but nothing so far mentioning the problem I've outlined here.

There is a folder for system32 on my Windows PC, but I'm trying for a single program that I can maintain and distribute to people running various operating systems. It would be self-defeating to have to copy my databases into system32.

This is the same basic code for connecting I've been using for over a year. There is, of course, no mention of system32.


        Connection conn = null;
        try {
            Class.forName("org.sqlite.JDBC");
            conn = DriverManager.getConnection("jdbc:sqlite:databases/Logic2.sqlite"); 
            return conn;
        }catch (Exception e)

The expected results are what I get on any Mac that I've tried it on, and the actual result when I run the same code on Windows 10 is that I only get one error message.

Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154

1 Answers1

1

The problem you're running in to is the default directory that the process is using.

On windows, it's apparently using c:\windows\system32.

On the Mac, it's using your applications folder.

So, you need to either specify an absolute path for your database URL, or you need to change your current working directory for your application.

Will Hartung
  • 115,893
  • 19
  • 128
  • 203
  • I thought that was the problem, however I am not going to be able to count on everybody with a PC running the same version of Windows. Moreover, the way I'm distributing this thing, to add lessons all the remote user needs to do is to place new DBs into the databases folder. And how about somebody running Linux? Is there some way to set an absolute path that will work for Macs and PCs? Thank you very much for your help. – user9695085 May 03 '19 at 16:46
  • @user9695085 A better solution is to have some kind of installer that puts your files in to a Known location, such as off of the user's home directory. The user.home system property can lead the way then. https://stackoverflow.com/questions/4871051/getting-the-current-working-directory-in-java has some techniques of locating your current work directory, but also techniques to find where you original jar is. That may help as well. Where a program is "installed" and what the "working directory" is can depend on all sorts of these across the operating systems and environments. – Will Hartung May 03 '19 at 20:43
  • @ Will Hartung. Have been perusing Q-A re using sqLite DBs & writing Javacode for making your own databases. Seemingly for software created & operating locally it doesn't matter where you locate your stuff. I'll copy the .java files for a simple version of my project (in Eclipse) and see whether I can get the same code to work on both. computers. The subdirectory "windows32" has mostly dll files, a small number of .exe files, and a very small number of ,png files. In one stack overflow discussion, somebody claimed databases are hidden from their authors deliberately by DB managers. Bonkers? – user9695085 May 04 '19 at 07:12
  • @user9695085 you put the files anywhere, but you shouldn't. For example that windows32 directory "isn't yours", it's the systems. You don't know what will or will not go in there in the future. On Linux systems, there are different practices of what files go where (and different distros standards vary from others). On Mac, there are also different standards. At a minimum, asking the user where they want to put something rarely goes wrong. You can look at the Java Preferences API to record their choice for posterity across program invocations so it won't "forget". – Will Hartung May 04 '19 at 15:38