First you need to install navicat for SQL server software,
In order to connect Matlab to the Sqlserver database through JDBC, the Sqlserver JDBC driver needs to be installed. Address:
https://blog.csdn.net/yinxing408033943/article/details/7677769
Experiment in navicat for SQL server, log in and enter the user name,
New query, a simple query example
Send some shortcut keys for Navicat sql:
ctrl + /: comment
ctrl + shift + /: uncomment
ctrl + l: delete a line
The implementation in matlab is as follows: Create a new function getConn()
% Connect to the database to get data
function conn=getConn()
% Database url
databaseurl='jdbc:sqlserver://10.2.224.56:1433;database=newwind'; % Modify as needed
% jdbc driver
driver='com.microsoft.sqlserver .jdbc.SQLServerDriver'; %driver
% login
username='***';
% password
password='****';
% data source name
databasename='newwind';
% get connection to database
conn = database( databasename,username,password,driver,databaseurl);
% % If the connection is not successful, throw an error and display the reason
% if ~isconnection(conn)
% error('Connection to database ''%s'' failed: %s', databasename, conn.Message);
% end
Next, create a new script get_data
tt1= ''' 20160930 '' , '' 20161231 ''' ; code_sql='''000001.SZ'',''002808.SZ'''; conn=getConn(); sql=['select s.report_period ,s.s_info_windcode,a.s_fa_eps_basic,a.TOT_OPER_REV ',... ' from (select DISTINCT t.report_period,t.s_info_windcode from ASHAREINCOME t',... [' where t.report_period IN(',tt1],... [')and t.s_info_windcode IN (',code_sql],... ')) s full join (SELECT report_period,s_info_windcode,s_fa_eps_basic ,TOT_OPER_REV',... [' from ASHAREINCOME where report_period IN(',tt1],... [') and statement_type=''408001000''and s_info_windcode IN (',code_sql],... ')) a on s.report_period=a.report_period and s.s_info_windcode=a.s_info_windcode',... ' order by s.s_info_windcode, s.report_period']; curs = exec(conn,sql); course = fetch (course); data_try= curs.Data; size(data_try)
got the answer
!!!Note: The wind account is generally provided by the company and can only be used on the company's intranet.