I am encountering an error when trying to connect to my SWLite db file. I want to create a simple web app to add to my portfolio which shows I can use an SQL DB. When I click on test connections, It says I am properly connected. Once I close the connections window I get the following error message –
Unable to attach database file database.db: [SQLITE_CANTOPEN] Unable to open the database file (unable to open database: database.db)
I am using IntelliJ Community edition with the DB Browser plugin.
I have tried double checking the file paths and they seem correct. I will attach a picture for my project file path as well. You can see the code below:
public static void main(String[] args) {
SpringApplication.run(CarScreenerApplication.class, args);
String url = "jdbc:sqlite:src/main/database/database.db";
try {
Connection connection = DriverManager.getConnection(url);
System.out.println("Connected to the database.");
connection.close();
} catch (SQLException e) {
System.out.println("Error connecting to the database");
}
}
I also tried executing the schema.sql file for my project which has no effect on the database file. Additionally, when I try to run the schema file it says that to schema is selected, but that of course is because the file I want to run is supposed to set up the schema:
CREATE TABLE IF NOT EXISTS cars (
id INTEGER PRIMARY KEY,
make TEXT,
model TEXT,
year INTEGER,
incidentsPer1000 INTEGER
);
I feel like the issue is how I am using the DB browser connection but I have never used this tool before so I am not sure. In picture 2 you see under properties that autocommit is off, I read that turning it on could fix this but when I tried that it still said I was not connected.
Database connection settings
Database connection settings 2
Database connection settings 3
Database file path
nick639 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.