Database Toolbox - datainsert error
조회 수: 1 (최근 30일)
이전 댓글 표시
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
Jayaram Theegala
2017년 4월 6일
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.
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Database Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!