MATLAB DATABASE TOOLBOX RELEASE NOTES User's Guide Page 371

  • Download
  • Add to my manuals
  • Print
  • Page
    / 684
  • Table of contents
  • BOOKMARKS
  • Rated. / 5. Based on customer reviews
Page view 370
Exporting Data Using Bulk Insert
6-29
Tip When connecting to a database on a remote machine, you must write this file to
the remote machine. Microsoft SQL Server has problems trying to read files that are
not on the same machine as the instance of the database.
fid = fopen('c:\temp\tmp.txt','wt');
for i = 1:size(A,1)
fprintf(fid,'%10.2f \t %s \t %s \t %s \n',A{i,1},...
A{i,2},A{i,3},A{i,4});
end
fclose(fid);
6
Run the bulk insert.
e = exec(conn,['bulk insert BULKTEST from '...
'''c:\temp\tmp.txt''with (fieldterminator = ''\t'', '...
'rowterminator = ''\n'')']);
7
Confirm the number of rows and columns in BULKTEST.
e = exec(conn, 'select * from BULKTEST');
results = fetch(e)
results =
Attributes: []
Data: {10000x4 cell}
DatabaseObject: [1x1 database]
RowLimit: 0
SQLQuery: 'select * from BULKTEST'
Message: []
Type: 'Database Cursor Object'
ResultSet: [1x1 com.microsoft.sqlserver.jdbc.SQLServerResultSet]
Cursor: [1x1 com.mathworks.toolbox.database.sqlExec]
Statement: [1x1 com.microsoft.sqlserver.jdbc.SQLServerStatement]
Fetch: [1x1 com.mathworks.toolbox.database.fetchTheData]
columnnames(results)
ans =
'salary','player','signed_date','team'
8
Close the connection.
Page view 370
1 2 ... 366 367 368 369 370 371 372 373 374 375 376 ... 683 684

Comments to this Manuals

No comments