Use CLI to develop DB2 Stored Procedure instances (1)

Source: Internet
Author: User

The stored procedure is one of the most important issues to consider when using a large relational database DB2 for development. This article describes how to use CLI to develop the DB2 stored procedure and attaches a development instance for your reference.

  • Actual operations for viewing DB2 dynamic SQL and Stored Procedure SQL
  • What code is used for writing DB2 stored procedures?
  • What types of abnormal processors are involved in DB2 stored procedures?
  • Quick Start to DB2 Stored Procedure"
  • Errors frequently encountered when creating a stored procedure in DB2 are:

■ DB2 Stored Procedure

Stored Procedure Store Procedure) is a programming method in the Client/Server application. It is mainly used to solve the network overload problems that may occur when the Client application accesses the database.

In general, DB2 provides three methods for writing stored procedures, not directly using the DB2 Store Procedure Builder generation method): the first is embedded SQL programming; the second is CLI programming, and the third is pure SQL programming. This article focuses on CLI programming.

■ CLI Programming

CLICall Level Interface) programming is a way that DB2 provides to write a dynamic database read/write program. In CLI programming, all SQL statements are executed through a set of C language functions provided by DB2, so they can be directly developed in Visual Studio. Next, we first need to briefly introduce the working process and method of CLI.

The CLI program consists of three parts: Environment Variable initialization, statement execution, and environment variable release. We will use a specific example to discuss these three processes.

■ Development Instance

The database in this example is a Sample database automatically generated by DB2. The operation completed in this example is to obtain the employee name whose ID is equal to the input parameter value from the database. The entire process of this example is very simple, however, it includes the basic ideas and steps for CLI programming.

1. initialize Environment Variables

There are three handles in CLI: Environment handle, connection handle, and statement handle. During initialization, you must first obtain the first two handles one by one. After successful retrieval, you can connect to the database and obtain the third handle.

SQLRETURN ret;

SQLHENV henv; // environment handle

SQLHDBC hdbc; // connection handle

SQLHSTMT hstmt; // statement handle

Sqlchar dbname [] = "SAMPLE"; // Database Name


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.