gpt4 book ai didi

java - 带有 Ormlite 和 JavaFX 的嵌入式 Sqlite 数据库 : error creating table

转载 作者:行者123 更新时间:2023-11-30 07:33:56 32 4
gpt4 key购买 nike

我正在尝试在我的 JavaFX 应用程序中保留一些数据。尝试在 PersistenceManager 类中创建表时,我的代码失败:

private final static String DATABASE_URL = "jdbc:sqlite:my.db";
private final static String DATABASE_DRIVER = "org.sqlite.JDBC";
// ...
Class.forName(DATABASE_DRIVER);
DriverManager.getConnection(DATABASE_URL);
connectionSource = new JdbcConnectionSource(DATABASE_URL);
// here it fails:
TableUtils.createTable(connectionSource,MyClass.class);

实际上创建了一个文件my.db,但它是空的。执行TableUtils.createTable时,会触发以下操作:

Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1771)
... 43 more
Caused by: java.lang.AbstractMethodError: com.j256.ormlite.jdbc.JdbcDatabaseConnection.compileStatement(Ljava/lang/String;Lcom/j256/ormlite/stmt/StatementBuilder$StatementType;[Lcom/j256/ormlite/field/FieldType;I)Lcom/j256/ormlite/support/CompiledStatement;
at com.j256.ormlite.table.TableUtils.doStatements(TableUtils.java:458)
at com.j256.ormlite.table.TableUtils.doCreateTable(TableUtils.java:441)
at com.j256.ormlite.table.TableUtils.createTable(TableUtils.java:221)
at com.j256.ormlite.table.TableUtils.createTable(TableUtils.java:54)
at org.lh.mypackage.mysubpackage.PersistenceManager.<init>(PersistenceManager.java:32)

我的类(class)是这样的:

@DatabaseTable(tableName = "myclass")
public class MyClass {
@DatabaseField(id = true)
private String nome;

@ForeignCollectionField(eager = false)
private Collection<MyOtherClass> risposte;

protected MyClass() {
super();
}
}

而 MyOtherClass 是:

@DatabaseTable(tableName = "myotherclass")
public class MyOtherClass {
@DatabaseField(id = true)
private String nome;

@DatabaseField(foreign = true)
private MyClass scheda;

protected MyOtherClass() {
super();
}
}

我正在使用ormlite-core-4.49-SNAPSHOT.jar

我应该寻找什么来纠正这个问题?

最佳答案

对我来说,解决方案是切换到 ormlite-core-4.48。 ormlite-jdbc 驱动程序的版本相同。现在它可以正常工作了。

关于java - 带有 Ormlite 和 JavaFX 的嵌入式 Sqlite 数据库 : error creating table,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35681204/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com