HSQDLDB引入加密数据库时会抛出ArrayIndexOutOfBoundsException异常。

huangapple go评论60阅读模式
英文:

HSQDLDB throws ArrayIndexOutOfBoundsException: when encrypted DB is introduced

问题

//java code in netbeans
//Registering the HSQLDB JDBC driver and getting connection  
Class.forName("org.hsqldb.jdbc.JDBCDriver");
con = DriverManager.getConnection("jdbc:hsqldb:file:C:\\Users\\PC\\mydb_fileencr;crypt_key=3f302916463bf54b10f5fc2b810ca43d;crypt_type=AES", "SA", "");

//creation of table
String sqlCreateTable = "CREATE TABLE PM (id INTEGER IDENTITY PRIMARY KEY, name varchar (500), submission_date date, file blob)";

//insertion code
String sqlInsert = "INSERT INTO PM (name, submission_date, file) VALUES (?, ?, ?)";

//values
pstmt = con.prepareStatement(sqlInsert);
String name = "John";
pstmt.setString(1, name);
pstmt.setDate(2, getCurrentDate());
pstmt.setBinaryStream(3, input); //the file is 1.3MB zip file and working fine

try {
    result = pstmt.executeUpdate();
} catch (java.sql.SQLException sq) {
    sq.printStackTrace();
}

//this code works fine within netbeans process when encryption key is not introduced in jdbc url.
//key is obtained by CALL CRYPT_KEY('AES', null); in hsqldb gui

//and the exception is

Connection created successfully
INSERT INTO PM (name, submission_date, file) VALUES (?, ?, ?)
java.sql.SQLException: java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 528384
    at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
    at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
    at org.hsqldb.jdbc.JDBCPreparedStatement.fetchResult(Unknown Source)
    at org.hsqldb.jdbc.JDBCPreparedStatement.executeUpdate(Unknown Source)
    at test.HSQLConnectDB.insert(HSQLConnectDB.java:130)
    at test.HSQLConnectDB.main(HSQLConnectDB.java:168)
query executed 0
Caused by: org.hsqldb.HsqlException: java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 528384
    at org.hsqldb.error.Error.error(Unknown Source)
    at org.hsqldb.SessionData.allocateLobForResult(Unknown Source)
    at org.hsqldb.Session.allocateResultLob(Unknown Source)
    at org.hsqldb.jdbc.JDBCPreparedStatement.performPreExecute(Unknown Source)
    ... 4 more
Caused by: java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 528384
    at org.hsqldb.persist.LobManager.deflate(Unknown Source)
    at org.hsqldb.persist.LobManager.setBytesBACompressedPart(Unknown Source)
    at org.hsqldb.persist.LobManager.setBytesBACompressed(Unknown Source)
    at org.hsqldb.persist.LobManager.setBytesBA(Unknown Source)
    at org.hsqldb.persist.LobManager.setBytes(Unknown Source)
    at org.hsqldb.SessionData.allocateBlobSegments(Unknown Source)
    ... 7 more

Please note that this code is a direct translation of the provided Java code into Chinese. Let me know if you need any further assistance or clarification.

英文:
    //java code in netbeans
//Registering the HSQLDB JDBC driver and getting connection  
Class.forName("org.hsqldb.jdbc.JDBCDriver");
con = DriverManager.getConnection("jdbc:hsqldb:file:C:\\Users\\PC\\mydb_fileencr;crypt_key=3f302916463bf54b10f5fc2b810ca43d;crypt_type=AES", "SA", "");
//creation of table
String sql = "CREATE TABLE PM (id INTEGER IDENTITY PRIMARY KEY, name varchar (500), submission_date date , file blob )";//PRIMARY KEY (id);
//insertion code
String sql = "INSERT INTO PM (name , submission_date , file ) values (?,?,?)";//PRIMARY KEY (id)
//values
pstmt = con.prepareStatement(sql);
String name = "John";
pstmt.setString(1, name);
pstmt.setDate(2, getCurrentDate());
pstmt.setBinaryStream(3, input); //the file is 1.3MB zip file and working fine
try {
result = pstmt.executeUpdate();
} catch (java.sql.SQLException sq) {
sq.printStackTrace();
}
//this code works fine within netbeans process when encryption key is not introduced in jdbc url.
//key is obtained by CALL CRYPT_KEY('AES', null); in hsqldb gui
//and the exception is
Connection created successfully
INSERT INTO PM (name , submission_date , file ) values (?,?,?)
java.sql.SQLException: java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 528384
at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCPreparedStatement.fetchResult(Unknown Source)
at org.hsqldb.jdbc.JDBCPreparedStatement.executeUpdate(Unknown Source)
at test.HSQLConnectDB.insert(HSQLConnectDB.java:130)
at test.HSQLConnectDB.main(HSQLConnectDB.java:168)
query executed 0
Caused by: org.hsqldb.HsqlException: java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 528384
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.SessionData.allocateLobForResult(Unknown Source)
at org.hsqldb.Session.allocateResultLob(Unknown Source)
at org.hsqldb.jdbc.JDBCPreparedStatement.performPreExecute(Unknown Source)
... 4 more
Caused by: java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 528384
at org.hsqldb.persist.LobManager.deflate(Unknown Source)
at org.hsqldb.persist.LobManager.setBytesBACompressedPart(Unknown Source)
at org.hsqldb.persist.LobManager.setBytesBACompressed(Unknown Source)
at org.hsqldb.persist.LobManager.setBytesBA(Unknown Source)
at org.hsqldb.persist.LobManager.setBytes(Unknown Source)
at org.hsqldb.SessionData.allocateBlobSegments(Unknown Source)
... 7 more

Code is written in java using Netbeans. Also i want to ask, if i insert data in hsqldb using file mode:my specified directory and also insert data using hsqldb GUI, then conflict occurs and multiple exceptions are raised but anyways my preference is to check how encryption is applied in hsqldb. please help if some "complete" sample code is available

答案1

得分: 1

如果您使用最新版本2.5.1并创建新数据库,您无需在连接URL中使用crypt_lobs=true(它会自动完成)来加密LOB文件。ArrayindexOutOfBoundsException是由一个在版本2.5.1中已修复的错误引起的。如果您发现任何问题,您可以报告给HSQLDB项目。

关于crypt_lobs=false的建议适用于使用较旧版本的HSQLDB创建的数据库,不适用于新数据库。对于新数据库和最新版本,您根本不需要设置此属性。

英文:

If you use the latest version 2.5.1 and create a new database, you do not need to use crypt_lobs=true in your connection URL (it is done automatically) to encrypt the lob files. The ArrayindexOutOfBoundsException was due to a bug that has been finxed in version 2.5.1. If you find any issue, you can report for the HSQLDB project.

The advice given about crypt_lobs=false is for databases created using much older versions of HSQLDB and does not apply to new databases. With new databases and the latest versions, you do not need to set this property at all.

huangapple
  • 本文由 发表于 2020年7月24日 01:07:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/63059591.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定