Error while executing 'onCleanup' class destructor with sqlwrite() to PostgreSQL

4 views (last 30 days)
Hello Friends,
i am using sqlwrite() in a Matlab App.
% csvDataToImport is a table
sqlwrite(app.conn, 'my_SQLTable', csvDataToImport)
The connection works fine.
The connection is open until the App is closed than the connection gets closed "close(app.conn)".
However when this line is executed i get following error.
Warning: The following error was caught while executing 'onCleanup' class destructor:
Error using database.jdbc.connection/sqlwriteHook>@()close(metaStmt)
Java exception occurred:
java.lang.ClassCastException
at
java.util.concurrent.atomic.AtomicIntegerFieldUpdater$AtomicIntegerFieldUpdaterImpl.throwAccessCheckException(AtomicIntegerFieldUpdater.java:475)
at
java.util.concurrent.atomic.AtomicIntegerFieldUpdater$AtomicIntegerFieldUpdaterImpl.accessCheck(AtomicIntegerFieldUpdater.java:466)
at
java.util.concurrent.atomic.AtomicIntegerFieldUpdater$AtomicIntegerFieldUpdaterImpl.compareAndSet(AtomicIntegerFieldUpdater.java:488)
at org.postgresql.jdbc.PgStatement.close(PgStatement.java:679)
Error in onCleanup/delete (line 25)
obj.task();
Error in database.jdbc.connection/sqlwriteHook (line 22)
c = onCleanup(@()closeStatement(insertStmt));
Error in database.relational.connection/sqlwrite (line 187)
sqlwriteHook(conn,tablename,data,columnnames,newTableCreated)
It still works (csvDataToImport is written in the PostgreSQL Databank).
I am using the newest JDBC driver and do not have problems with other commands like exec() or fetch().
How do i fix this error?
Thank you a lot for heling me!

Accepted Answer

Tim
Tim on 11 Mar 2025
If anybody else has this problem:
Do not use
javaaddpath(jdbcPath);
use JDBCDriverLocation instead.
app.conn = database(datenbankName, username, password, ...
'Vendor', 'PostgreSQL', 'Server', Server, 'PortNumber', PortNumber,...
'JDBCDriverLocation', jdbcPath);
This will fix your problem.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!