Я пытаюсь написать приложение Java для подключения к памяти в sqlite db с помощью maven. Я также добавил зависимость SQLite в файл pom.xml.Когда я запускаю программу, я получаю ошибки:
"java.lang.ClassNotFoundException: org.sqlite.JDBC" и "Не найден подходящий драйвер для jdbc: sqlite: myDB.sqlite".
Пожалуйста, дайте мне знать, если я что-то упустил.Спасибо!
public class Application {
public static void main(String[] args) throws ClassNotFoundException{
System.out.println("Application class created\n");
Connection connection = null;
try {
Class.forName("org.sqlite.JDBC");
}catch (ClassNotFoundException e){
System.err.println("Class not found"+e);
}
try{
connection = DriverManager.getConnection("jdbc:sqlite::memory:");
Statement statement = connection.createStatement();
statement.setQueryTimeout(33);
statement.executeUpdate("create table demo (id integer, name string)");
statement.executeUpdate("insert into demo(1, 'A')");
ResultSet mySet = statement.executeQuery("select * from demo");
while(mySet.next()){
System.out.println("Name is : "+mySet.getString("name"));
System.out.println("Id is : "+mySet.getInt("id"));
}
}
catch (SQLException sqlException){
System.err.println(sqlException.getMessage());
}
finally {
try{
if(connection!=null)
connection.close();
}
catch (SQLException sqlException){
System.err.println(sqlException);
}
}
}
}
Моя зависимость файла POM:
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<!-- https://mvnrepository.com/artifact/org.xerial/sqlite-jdbc -->
<dependencies>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.23.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<mainClass>path-to-mainclass-Application</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>