Error while inserting data into sql server
19 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Kojiro Saito
am 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?
Antworten (1)
Kojiro Saito
am 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 Kommentare
Siehe auch
Kategorien
Mehr zu Database Toolbox finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!