JDBC Connection DB2 Database detailed

Source: Internet
Author: User
Tags db2 db2 client zip port number tomcat

About DB2 database JDBC Connection article has many, the more famous has such as "the JDBC Database connection encyclopedia" and "the JSP DB2 Connection database", although all is very detailed information, also all said solves the predecessor not to solve the problem, but still has many flaws. I've been writing an article about JDBC Connection database for the last two days to address some people's questions.

First: JDBC is part of the JDK (at least in javatigerdevelopmentkits), using JDBC to write importjava.sql.* directly in the program file;

Second: The format of the connection string. The connection string for the local connection is formatted as jdbc:product_name:database_name and the remote connection is in the format: Product_name://host_name/port_

Number:database_name. That is, if my database name is RDB, the local connection string is Jdbc:db2:rdb (of course RDB must be in the default instance of DB2), and the remote connection string is jdbc:db2:// RDB (here is the server IP address for the database, and 50000 is the port number for the DB2 connection service).

Third: Install the class library for JDBC provided by the DB2 database (called provider in. NET, not yet studied in Java). Find Ibmdb2udb's installation directory or Java Tiger's JDK directory you'll find Db2java.zip, make a copy of it first and then it's most useful. Now we're going to start talking about the program code for the database connection.

Application Connection DB2 Database:

First unzip the db2java.zip, transfer the COM directory to the current directory of the code, and then we start registering the provider instance with the code:

Class.forName ("COM.ibm.db2.jdbc.app.DB2Driver"). newinstance ();

Class.forName ("COM.ibm.db2.jdbc.net.DB2Driver"). Newinstance ():

The two sentences are optional, the effect is slightly different, the former is a provider instance with DB2 client, the latter is a provider instance without DB2 client.

Then write Connectioncon=drivermanager.getconnection (), and you can get an instance of the database connection.

Connect DB2 database in JSP:

This takes Tomcat as a servlet container, and if you want to use DB2 in Tomcat

Provider must rename Db2java.zip to Db2java.jar and copy it to the Tomcat home directory C

Well, I hope you make progress every day,!!!.

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.