Java programming steps for connecting to the DB2 database to develop applications

Source: Internet
Author: User

We have introduced the implementation process of the DB2 database creation trigger and the methods and examples of calling the stored procedure of the DB2 database. In this article, we will introduceDB2Some steps for database Java programming. Next let's take a look at this process.

Java Database Link (JDBC)

DB2 Java supports JDBC, a supplier-centric dynamic SQL interface, which provides data access to applications through standard Java methods. JDBC is similar to DB2 CLI in that you do not have to pre-compile or compile JDBC programs. Applications compiled using JDBC only use dynamic SQL.

JDBC programming steps:

1. Establish a connection with the database:

 
 
  1. Class.forName("Com.ibm.db2.jdbc.net.DB2Driver");  
  2.  
  3. connection con=DriverManager.getConnection(url); 

2. Create a Statement object:

 
 
  1. Statement stmt=con.createStatement(); 

3. Execute the query statement:

 
 
  1. ResultSet rs1_stmt.exe cQuery ("SQL statement ");

4. Get and set options:

ResultSetMetaData rsmd = rs. getMetaData ();

Int numCols = rsmd. getColumnCount () to obtain the total number of columns in the result set;

Rsmd. getColumnLabel (I) to obtain the record value;

SetMaxRows: set the maximum number of rows that a result set can accommodate.

SetQueryTimeout: Set the waiting time for a statement to be executed.

SetEscapeProcessing: notifies the driver of how to handle escape characters.

5. Disable Statement

 
 
  1. stmt.clost(); 

Call layer interface (CLI)

CLI is not a new query language, but a simple interface for applications to use SQL statements to submit transactions for database query and modification, you still need to write it in SQL, including calling CLI functions.

The call layer interface (CLI) is one of the two mechanisms provided by DB2 to process dynamic SQL statements. That is, when an application is running for the first time, dynamic SQL statements are submitted to the database system, CLI depends on a group of function calls and can be embedded in the subject.

This article introduces the JDBC programming steps for DB2 databases and hopes to help you gain some benefits!

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.