I'm trying to connect my java application to my sqlite database but I'm getting this good old error. I'm using Maven and my setup looks like this:
I'm using IntelliJ and as far as I know Maven is well integrated. I'd like to know If I need to add the library somewhere else or put the jar file on the classpath.
I also leave here my pom.xml file with project definitions
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Maven Quick Start Archetype</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.16.1</version>
</dependency>
</dependencies>
</project>
This is my connection class:
package database;
import java.io.File;
import java.io.FileNotFoundException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
/**
* Created by luiscosta on 3/29/17.
*/
public class DBConnection {
private Connection conn;
private String dbPath;
/**
* Constructor
*/
public DBConnection(String name, String folder) throws FileNotFoundException {
File dbDir = new File(folder);
if (dbDir.isDirectory() && dbDir.exists()) { //confirms the database directory exists
if (folder.charAt(folder.length() - 1) == '/') { //checks if the directory ends in /
this.dbPath = folder + name;
} else {
this.dbPath = folder + '/' + name; //if not adds it in the end of the folder pah
}
//Connection
try {
Class.forName("org.sqlite.JDBC");
System.out.println("db Path" + this.dbPath);
this.conn = DriverManager.getConnection("jdbc:sqlite:ChunkMetaData");
} catch (Exception e) {
e.printStackTrace();
}
} else {
throw new FileNotFoundException("Directory not found!");
}
}
}