User`s guide
datainsert
7-91
close(conn)
Export MATLAB Numeric Matrix Data
Establish connection conn to a MySQL database with user name username and
password pwd. This database contains the table salesVolume with the column
stockNumber and columns for each month of the year.
conn = database('MySQL','username','pwd');
Display the last rows in salesVolume before inserting data.
curs = exec(conn,'select * from salesVolume');
curs = fetch(curs);
curs.Data
ans =
Columns 1 through 8
...
[470816] [3100] [9400] [1540] [1500] [1350] [1190] [ 900]
[510099] [ 235] [1800] [1040] [ 900] [ 750] [ 700] [ 400]
[899752] [ 123] [1700] [ 823] [ 701] [ 689] [ 621] [ 545]
Columns 9 through 13
...
[867] [ 923] [1400] [ 3000] [35000]
[350] [ 500] [ 100] [ 3000] [18000]
[421] [ 495] [ 650] [ 4200] [11000]
Create a cell array of column names for the database table salesVolume.
colnames = {'stockNumber','January','February'...
'March','April','May',...
'June','July','August',...
'September','October','November',...
'December'};
Define the numeric matrix data that contains the sales volume data.
data = [777666,0,350,400,450,250,450,500,515,...
235,100,300,600];
Insert the contents of data into the table salesVolume using database connection conn.