Error while inserting data into sql server

조회 수: 19 (최근 30일)
jothi
jothi 2018년 1월 4일
답변: Kojiro Saito 2018년 1월 5일
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
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?
jothi
jothi 2018년 1월 5일
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..

댓글을 달려면 로그인하십시오.

답변 (1개)

Kojiro Saito
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.

카테고리

Help CenterFile Exchange에서 Database Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by