Example: Input and Output Arguments in JDBC - Teradata Database - Teradata Vantage NewSQL Engine

SQL Data Manipulation Language

Product
Teradata Database
Teradata Vantage NewSQL Engine
Release Number
16.20
Published
March 2019
Language
English (United States)
Last Update
2019-05-03
dita:mapPath
fbo1512081269404.ditamap
dita:ditavalPath
TD_DBS_16_20_Update1.ditaval
dita:id
B035-1146
lifecycle
previous
Product Category
Teradata Vantage™

Consider the stored procedure spSample2, which can be executed using the following JDBC API calls:

     CallableStatement cstmt = con.prepareCall("CALL spSample2(p1, ?,      ?)");
     ResultSet rs = cstmt.executeQuery();

The following alternatives can be used for the second line (ResultSet rs = …):

     boolean bool = cstmt.execute();

or

     int count = cstmt.executeUpdate();

The QUESTION MARK character indicates an argument and acts as a placeholder for IN or INOUT parameters in the prepareCall() request. The question mark placeholder arguments must be bound with the application local variables and literals using the CallableStatement.setXXX() JDBC API calls.

Alternatively, an IN or INOUT argument can be a constant expression.

The INOUT and OUT arguments need to be registered using the following JDBC API call:

     CallableStatement.registerOutParameter()

After execution the parameter values can be retrieved from the response using the CallableStatement.getXXX() JDBC API calls.