Код: Выделить всё
No suitable driver found for jdbc:h2:./diary;INIT=RUNSCRIPT FROM 'classpath:diaries.sql';
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:638)
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:222)
at edu.ntnu.idi.idat.TestCode.main(TestCode.java:18)
Код: Выделить всё
java -jar target/project-1.0-SNAPSHOT.jar
Код: Выделить всё
java -cp target/classes/ edu.ntnu.idi.idat.TestCode
Я пробовал переместить файл JAR по папке моего проекта, из целевой папки в корень папки проекта и даже в папку, где у меня есть файл TestCode.java.
В сообщении с аналогичной ошибкой упоминаются загрузчики классов. Я не уверен, что это такое, и я ничего с этим не делал, поэтому не думаю, что это имеет отношение к моей проблеме, хотя могу ошибаться.
Код:
Код: Выделить всё
package edu.ntnu.idi.idat;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public final class TestCode {
private TestCode() { }
/**
* Test code.
* @param args
*/
public static void main(
final String[] args
) {
try {
Connection connection = DriverManager.getConnection(
"jdbc:h2:./diary;INIT=RUNSCRIPT FROM 'classpath:diaries.sql';"
);
System.out.println(
"connection.isValid() = "
+ connection.isValid(0)
);
} catch (SQLException e) {
e.printStackTrace();
}
}
}
Код: Выделить всё
pom.xml:
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
edu.ntnu
project
1.0-SNAPSHOT
project
http://www.example.com
UTF-8
1.8
1.8
junit
junit
4.11
test
com.h2database
h2
2.4.240
org.springframework
spring-core
7.0.0-M9
org.springframework.security
spring-security-core
7.0.0-RC1
org.springframework.security
spring-security-crypto
7.0.0-RC2
com.google.guava
guava-primitives
r03
org.apache.maven.plugins
maven-jar-plugin
3.5.0
true
edu.ntnu.idi.idat.TestCode
maven-clean-plugin
3.1.0
maven-resources-plugin
3.0.2
maven-compiler-plugin
3.8.0
maven-surefire-plugin
2.22.1
maven-jar-plugin
3.0.2
maven-install-plugin
2.5.2
maven-deploy-plugin
2.8.2
maven-site-plugin
3.7.1
maven-project-info-reports-plugin
3.0.0
org.apache.maven.plugins
maven-compiler-plugin
3.8.1
11
11
--add-exports=java.base/com.sun.crypto.provider=ALL-UNNAMED
Код: Выделить всё
diaries.sql:
create table if not exists DIARIES (id identity primary key, title varchar (255) not null, author varchar (255) not null, dating TIMESTAMP not null, diarytype varchar (255) not null, public BOOLEAN not null, password varchar(255), contents MEDIUMBLOB (100000) not null);

Подробнее здесь: https://stackoverflow.com/questions/798 ... a-jar-file
Мобильная версия