Define a stored procedure named productsWithinUnitCost
that
returns the product number and description for products that have
a unit cost in a specified range by executing this code. This procedure
has two input arguments minUnitCost
and maxUnitCost
.
This procedure has two output arguments productno
and productdesc
.
This code assumes you are using a Microsoft
SQL Server database.
Create a Microsoft
SQL Server database
connection conn
using the JDBC driver. For details,
see Connecting to Database. Then, call the stored procedure
using:
Database connection conn
Stored procedure productsWithinUnitCost
Input arguments inputargs
to specify
a unit cost between 19 and 21
Output Java data types outputtypes
to
specify numeric and string data types for product number and description
results =
[1x1 java.math.BigDecimal]
'Snacks'
results
returns a cell array that contains
the product number as a Java decimal data type and the product
description as a string.
Display the product number in results
.
The product with product number 15 has a unit cost between 19
and 21.
Display the product description in results
.
The product with product number 15 has the product description Snacks
.
Here, the narrow unit cost range returns only one product. If
the unit cost range is wider, then more than one product might satisfy
this condition. To return a data set with numerous products, use exec
and fetch
to
call this stored procedure. Otherwise, runstoredprocedure
returns
only the last row in the data set.
Close the database connection conn
.