Martin Lundberg
Martin Lundberg

Reputation: 182

How to access an existing SQLite Database from another project in Eclipse

I have 2 projects in Eclipse. The first project calls a method from the second project handing it an object the second project shall write into an existing SQLite Database residing in the second project. However, I get the following error:

opening db: 'tomato.db': Zugriff verweigert

Zugriff verweigert is German for access denied.

How can I allow the db access from the first project to the database file tomato.db residing in the second project?

Upvotes: 0

Views: 2476

Answers (1)

Martin Lundberg
Martin Lundberg

Reputation: 182

Solution

I use sqlite-jdbc from xerial. In their tutorial they get the database connection with this line:

  connection = DriverManager.getConnection("jdbc:sqlite:yourdatabasefile.db");

However, this doesn't work from another project in Eclipse. The solution is actually pretty trivial:

  connection = DriverManager.getConnection("jdbc:sqlite:C:\\path\\to\\your\\database\\file\\yourdatabasefile.db");

Another solution is to use the in-memory sqlite database like this:

connection = DriverManager.getConnection("jdbc:sqlite::memory:");

Hope this helps.

Upvotes: 2

Related Questions