javadatabasesqlitejimfs

SQLite + Virtual File System?


I'm using an SQLite database and I want to open a .db file from within a Jimfs virtual file system. Using the following code I can import a file into the virtual file system:

String databaseFilePath = "...";
Configuration configuration = Configuration.unix();
FileSystem fileSystem = Jimfs.newFileSystem(configuration);
Path targetDirectory = fileSystem.getPath("/");
Files.copy(Paths.get(databaseFilePath), targetDirectory);

Next, when I try to open the database file, I'm running into problems:

Connection connection = DriverManager.getConnection("jdbc:sqlite:" + databaseFileName);

I cannot use Strings since the virtual file can only be referenced using the Path object. How do I open a database connection using Paths?


Solution

  • SQLite works on 'real' files.

    To be able to store data elsewhere, you have to implement your own SQLite VFS. (This is not supported by every JDBC driver.)