Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inserting data into PostgreSQL table from MATLAB with JDBC throws BatchUpdateException

I am trying to write to a PostgreSQL database table from MATLAB. I have got the connection working using JDBC and created the table, but I am getting a BatchUpdateException when I try to insert a record.

The MATLAB query to insert the data is:

user_table = 'rm_user';
colNames = {user_id};
data = {longRecords(iterator)};
fastinsert(conn, user_table, colNames, data);

The exception says:

java.sql.BatchUpdateException: Batch entry 0 INSERT INTO rm_user (user_id) VALUES ( '4') was aborted.  Call getNextException to see the cause.

But I don't know how to call getNextException from MATLAB.

Any ideas what's causing the problem or how I can find out more about the exception?

EDIT

Turns out I was looking at documentation for a newer version of MATLAB than mine. I have changed from fastinsert to insert and it is now working. However, I'm still interested in knowing if there is a way I could use getNextException from MATLAB.

like image 981
Pikaling Avatar asked Sep 04 '26 16:09

Pikaling


1 Answers

This should work:

try
   user_table = 'rm_user';
   colNames = {user_id};
   data = {longRecords(iterator)};
   fastinsert(conn, user_table, colNames, data);
catch err
   err.getNextException ()
end

Alternatively, just look at the caught error, it should contain the same information.

Also, Matlab has a function lasterr which will give you the last error without a catch statement. The function is deprecated, but you can find the documentation for replacements at the link provided.

like image 196
PearsonArtPhoto Avatar answered Sep 07 '26 07:09

PearsonArtPhoto



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!