Error while inserting data into sql server

19 visualizaciones (últimos 30 días)
jothi
jothi el 4 de En. de 2018
Respondida: Kojiro Saito el 5 de En. de 2018
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 comentarios
Kojiro Saito
Kojiro Saito el 5 de En. de 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?
jothi
jothi el 5 de En. de 2018
Data looks like...
2018-01-01 00:00:00,1.316252
2018-01-01 00:01:00,1.323807
2018-01-01 00:02:00,1.331343
2018-01-01 00:03:00,1.338859
2018-01-01 00:04:00,1.346356 pAerialbay is the tablename i given.. matlab 2017a..sql server 2008..

Iniciar sesión para comentar.

Respuestas (1)

Kojiro Saito
Kojiro Saito el 5 de En. de 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.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by