2
私はHSQLDBを初めて使っていて、このエラーが出てインターネット上でこれを解決する方法が見つからないのですが、何か不足しているようです^^HSQLDB - 整合性制約違反:一意制約またはインデックス違反。 BLOCKS_PKテーブル:BLOCKS
私のアプリケーションは現在すでに存在しない場合は2つのテーブルを作成する以外は何もしません。
これはHSQLDBを扱う私のコードです:
try {
Class.forName("org.hsqldb.jdbc.JDBCDriver");
} catch (Exception e) {
System.err.println("ERROR: failed to load HSQLDB JDBC driver.");
e.printStackTrace();
return;
}
try {
connection = DriverManager.getConnection("jdbc:hsqldb:file:"+mi.getDataFolder().getPath()+"\\data\\storage;hsqldb.lock_file=false", "SA", "");
connection.prepareStatement(
"CREATE TABLE IF NOT EXISTS Punishments (" +
"id INTEGER IDENTITY PRIMARY KEY," +
"name VARCHAR(16)," +
"uuid VARCHAR(35)," +
"reason VARCHAR(100)," +
"operator VARCHAR(16)," +
"punishmentType VARCHAR(16)," +
"start BIGINT," +
"end BIGINT," +
"calculation VARCHAR(50))"
).execute();
connection.prepareStatement(
"CREATE TABLE IF NOT EXISTS PunishmentHistory (" +
"id INTEGER IDENTITY PRIMARY KEY," +
"name VARCHAR(16)," +
"uuid VARCHAR(35)," +
"reason VARCHAR(100)," +
"operator VARCHAR(16)," +
"punishmentType VARCHAR(16)," +
"start BIGINT," +
"end BIGINT," +
"calculation VARCHAR(50))"
).execute();
} catch (SQLException e) {
e.printStackTrace();
}
私は、コードを実行する最初の2かそこら回、それが正常に動作しますが、いくつかの点で、私はこのエラーを取得しておいてください。
[22:22:21 FATAL]: statement error processing log - open continuedplugins\AdvancedBan\data\storage.log line: 2
org.hsqldb.HsqlException: integrity constraint violation: unique constraint or index violation; BLOCKS_PK table: BLOCKS
at org.hsqldb.error.Error.error(Unknown Source) ~[AdvancedBan-2.0.6-SNAPSHOT.jar:?]
at org.hsqldb.Constraint.getException(Unknown Source) ~[AdvancedBan-2.0.6-SNAPSHOT.jar:?]
at org.hsqldb.index.IndexAVLMemory.insert(Unknown Source) ~[AdvancedBan-2.0.6-SNAPSHOT.jar:?]
at org.hsqldb.persist.RowStoreAVL.indexRow(Unknown Source) ~[AdvancedBan-2.0.6-SNAPSHOT.jar:?]
at org.hsqldb.TransactionManager2PL.addInsertAction(Unknown Source) ~[AdvancedBan-2.0.6-SNAPSHOT.jar:?]
at org.hsqldb.Session.addInsertAction(Unknown Source) ~[AdvancedBan-2.0.6-SNAPSHOT.jar:?]
at org.hsqldb.Table.insertNoCheckFromLog(Unknown Source) ~[AdvancedBan-2.0.6-SNAPSHOT.jar:?]
at org.hsqldb.persist.ScriptRunner.runScript(Unknown Source) [AdvancedBan-2.0.6-SNAPSHOT.jar:?]
at org.hsqldb.persist.ScriptRunner.runScript(Unknown Source) [AdvancedBan-2.0.6-SNAPSHOT.jar:?]
at org.hsqldb.persist.Log.processLog(Unknown Source) [AdvancedBan-2.0.6-SNAPSHOT.jar:?]
at org.hsqldb.persist.Log.open(Unknown Source) [AdvancedBan-2.0.6-SNAPSHOT.jar:?]
at org.hsqldb.persist.Logger.open(Unknown Source) [AdvancedBan-2.0.6-SNAPSHOT.jar:?]
at org.hsqldb.Database.reopen(Unknown Source) [AdvancedBan-2.0.6-SNAPSHOT.jar:?]
at org.hsqldb.Database.open(Unknown Source) [AdvancedBan-2.0.6-SNAPSHOT.jar:?]
at org.hsqldb.DatabaseManager.getDatabase(Unknown Source) [AdvancedBan-2.0.6-SNAPSHOT.jar:?]
at org.hsqldb.DatabaseManager.newSession(Unknown Source) [AdvancedBan-2.0.6-SNAPSHOT.jar:?]
at org.hsqldb.jdbc.JDBCConnection.<init>(Unknown Source) [AdvancedBan-2.0.6-SNAPSHOT.jar:?]
at org.hsqldb.jdbc.JDBCDriver.getConnection(Unknown Source) [AdvancedBan-2.0.6-SNAPSHOT.jar:?]
at org.hsqldb.jdbc.JDBCDriver.connect(Unknown Source) [AdvancedBan-2.0.6-SNAPSHOT.jar:?]
at java.sql.DriverManager.getConnection(Unknown Source) [?:1.8.0_111]
at java.sql.DriverManager.getConnection(Unknown Source) [?:1.8.0_111]
at me.leoko.advancedban.manager.DatabaseManager.setup(DatabaseManager.java:69) [AdvancedBan-2.0.6-SNAPSHOT.jar:?]
[...]
これは、私はエラーを取得した後、ファイルがどのように見えるかの.logの例である:
/*C1*/SET SCHEMA SYSTEM_LOBS
INSERT INTO BLOCKS VALUES(0,2147483647,0)
COMMIT
/*C2*/SET SCHEMA PUBLIC
CREATE TABLE IF NOT EXISTS Punishments (id INTEGER IDENTITY PRIMARY KEY,name VARCHAR(16),uuid VARCHAR(35),reason VARCHAR(100),operator VARCHAR(16),punishmentType VARCHAR(16),start BIGINT,end BIGINT,calculation VARCHAR(50))
CREATE TABLE IF NOT EXISTS PunishmentHistory (id INTEGER IDENTITY PRIMARY KEY,name VARCHAR(16),uuid VARCHAR(35),reason VARCHAR(100),operator VARCHAR(16),punishmentType VARCHAR(16),start BIGINT,end BIGINT,calculation VARCHAR(50))
DISCONNECT
/*C4*/SET SCHEMA PUBLIC
CREATE TABLE IF NOT EXISTS Punishments (id INTEGER IDENTITY PRIMARY KEY,name VARCHAR(16),uuid VARCHAR(35),reason VARCHAR(100),operator VARCHAR(16),punishmentType VARCHAR(16),start BIGINT,end BIGINT,calculation VARCHAR(50))
CREATE TABLE IF NOT EXISTS PunishmentHistory (id INTEGER IDENTITY PRIMARY KEY,name VARCHAR(16),uuid VARCHAR(35),reason VARCHAR(100),operator VARCHAR(16),punishmentType VARCHAR(16),start BIGINT,end BIGINT,calculation VARCHAR(50))
DISCONNECT
/*C3*/SET SCHEMA PUBLIC
CREATE TABLE IF NOT EXISTS Punishments (id INTEGER IDENTITY PRIMARY KEY,name VARCHAR(16),uuid VARCHAR(35),reason VARCHAR(100),operator VARCHAR(16),punishmentType VARCHAR(16),start BIGINT,end BIGINT,calculation VARCHAR(50))
CREATE TABLE IF NOT EXISTS PunishmentHistory (id INTEGER IDENTITY PRIMARY KEY,name VARCHAR(16),uuid VARCHAR(35),reason VARCHAR(100),operator VARCHAR(16),punishmentType VARCHAR(16),start BIGINT,end BIGINT,calculation VARCHAR(50))
DISCONNECT
/*C3*/SET SCHEMA PUBLIC
CREATE TABLE IF NOT EXISTS Punishments (id INTEGER IDENTITY PRIMARY KEY,name VARCHAR(16),uuid VARCHAR(35),reason VARCHAR(100),operator VARCHAR(16),punishmentType VARCHAR(16),start BIGINT,end BIGINT,calculation VARCHAR(50))
CREATE TABLE IF NOT EXISTS PunishmentHistory (id INTEGER IDENTITY PRIMARY KEY,name VARCHAR(16),uuid VARCHAR(35),reason VARCHAR(100),operator VARCHAR(16),punishmentType VARCHAR(16),start BIGINT,end BIGINT,calculation VARCHAR(50))
私はバージョン2.4.0 Oを使用していますf HSQLDBでも以前のバージョンで試してみました
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>2.4.0</version>
<scope>compile</scope>
</dependency>
ありがとうございました。
古いバージョンのHSQLDBを使用している可能性があります。最新のものを試してください。 – fredt
@fredt私はHSQLDBの2.4.0を使用していますが、最新のものでなければなりません。私の質問も編集しました。とにかくお手伝いをしてくれてありがとう:) – Leoko
他のステートメントの後にconnection.prepareStatement( "CHECKPOINT")。execute()を追加して問題を修正する必要があります。 – fredt