User`s guide
6 Using Database Toolbox Functions
6-28
results =
Attributes: []
Data: {10000x4 cell}
DatabaseObject: [1x1 database]
RowLimit: 0
SQLQuery: 'select * from BULKTEST'
Message: []
Type: 'Database Cursor Object'
ResultSet: [1x1 oracle.jdbc.driver.OracleResultSetImpl]
Cursor: [1x1 com.mathworks.toolbox.database.sqlExec]
Statement: [1x1 oracle.jdbc.driver.OracleStatementWrapper]
Fetch: [1x1 com.mathworks.toolbox.database.fetchTheData]
columnnames(results)
ans =
'SALARY','PLAYER','SIGNED','TEAM'
10
Close the connection.
close(conn)
Bulk Insert into Microsoft SQL Server 2005
1
Connect to the Microsoft SQL Server. For JDBC driver use, add the JAR file to the
MATLAB Java class path.
javaaddpath 'path\sqljdbc4.jar';
conn = database('databasename','user','password',...
'com.microsoft.sqlserver.jdbc.SQLServerDriver',...
'jdbc:sqlserver://machine:port;
database=databasename');
2
Create a table named BULKTEST.
e = exec(conn,['create table BULKTEST (salary '...
'decimal(10,2), player varchar(25), signed_date '...
'datetime, team varchar(25))']);
close(e)
3
Enter data records. A sample record appears as follows.
A = {100000.00,'KGreen','06/22/2011','Challengers'};
4
Expand A to a 10,000-record data set.
A = A(ones(10000,1),:);
5
Write data to a file for bulk insert.