Database Toolbox - datainsert error

1 view (last 30 days)
Lukas Mich
Lukas Mich on 1 Apr 2017
Commented: Lukas Mich on 6 Apr 2017
Hi All,
I'm having issues with the Database Toolbox function "datainsert" and I can't figure out what the hell is wrong with my code.
Please note that I changed names of the variable to make the below code cleaner, so typos may not be the problem.
DB_CONN = database(DB_NAME, DB_USER, DB_PW, 'Vendor', 'MySQL', 'Server',DB_SERVER);
datainsert(DB_CONN, 'test', colnames, data)
where 'colnames' is {1x7 cell} and 'data' is [4470x7 double].
In the datainsert function I receive the below error:
No method 'prepareStatement' with matching signature found for class 'com.mysql.jdbc.JDBC4Connection'
Error in database.jdbc.connection/fastinsert (line 166)
StatementObject = tmpConn.prepareStatement([startOfString tmpq]);
Any Ideas?
I tested many times, the DB connection ist ok (I can create tables, fetch manual queries, ...). I wanted to use the implemented Matlab functions instead of writing data with "INSERT INTO ..."
Thanks a lot in advance for your help.
EDIT: After some hours of debugging, I finally found the issue, which (in my opinion) seems to be a bug.
The 'datainsert' function fails at code line 208:
StatementObject = connect.Constructor.prepareStatement([startOfString tmpq]);
And the problem seems here, that the prepareStatement method of the Constructor object needs the input argument as a string, not as cell array. I was able to fix this issue in this line by using 'cell2mat'
StatementObject = tmpConn.prepareStatement(cell2mat([startOfString tmpq]));
By the way, I'm having this trouble with R2016b, and haven't tried it in R2017a so far.
  2 Comments
Jayaram Theegala
Jayaram Theegala on 6 Apr 2017
The issue that you are facing could be because of mismatch between the column type of the database and the data being sent. What are the data types of the fields in the database?
Can you insert into the same database using "exec" function? Also, can you change the "data" datatype from double matrix type to table data type and see if it fixes the issue.
Lukas Mich
Lukas Mich on 6 Apr 2017
Thanks Jayaram, for your reply.
But the data was all ok. I wrote above, that using an 'exec' statement "manually" via 'INSERT INTO TABLE xy ....' works with the same data.
Please see my EDIT above, I was able to find a "solution" ... * sighs *

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!