Error while inserting data into sql server
조회 수: 19 (최근 30일)
이전 댓글 표시
I am getting below error when inserting data data into sql server database.I am unable to insert the data into database.But the same time i am able to read the data from the same database.
No method 'setDouble' with matching signature found for class 'com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement'.
Error in database.jdbc.connection/fastinsert (line 308) StatementObject.setDouble(j,tmp) %DOUBLE
Error in database.jdbc.connection/insert (line 37) fastinsert(connect,tableName,fieldNames,data)
Error in rtv_prd_ins_2018 (line 13) insert(conn,'pAerialBay',{'dtm','prd'},dbdat);
Here is the code.
conn = database('dbname','user','pass','com.microsoft.sqlserver.jdbc.SQLServerDriver','jdbc:sqlserver://hostname:1433;database=dbname;');
[dat,wl]=textread('name.csv','%s %s','delimiter',','); dbdat=horzcat(dat,wl); insert(conn,'tablename',{'col1','col2'},dbdat);
댓글 수: 2
Kojiro Saito
2018년 1월 5일
I cannot reproduce this issue. Insert works without an error in MATLAB R2017b and SQL Server 2016 and col1 and col2 are defined as nchar. Which MATLAB/SQL Server versions do you use?
Could you provide a few sample data of name.csv? And what the column definition of pAerialBay table?
답변 (1개)
Kojiro Saito
2018년 1월 5일
I think you have set col2 as some numeric data type for example, float, but you're textscan col2 data from the csv file as a character, that's why data type conflict (No method 'setDouble' with matching) occurs.
Try reading as a table from csv files and set %f of col2.
conn = database('dbname','user','pass','com.microsoft.sqlserver.jdbc.SQLServerDriver','jdbc:sqlserver://hostname:1433;database=dbname;');
colnames = {'col1','col2'};
dbdatTable = readtable('name.csv', 'Format','%s%f');
dbdatTable.Properties.VariableNames{'Var1'} = 'col1';
dbdatTable.Properties.VariableNames{'Var2'} = 'col2';
insert(conn,'insertTest' , colnames, dbdatTable);
This will work.
댓글 수: 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!