Error while inserting data into sql server
5 views (last 30 days)
Show older comments
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 Comments
Kojiro Saito
on 5 Jan 2018
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?
Answers (1)
Kojiro Saito
on 5 Jan 2018
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 Comments
See Also
Categories
Find more on Database Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!