Methods for JSP to connect DB2 database with JDBC

Source: Internet
Author: User
Tags copy db2 connect sql stmt port number
js| Data | database

Database version: DB2 UDB v7.2
Server operating system: aix4.3.3

1, shut down the Web service on the server;
2. Stop the JDBC Listener process DB2JD,DB2JD typically starts with a 6789 port service,
First Use Ps-ef | grep DB2JD to see its process number.
Then stop with kill-9 < process number > command;
3, in the database server, into the/usr/lpp/db2_07_01/java12 directory, execution./USEJDBC2 to enable JDBC2;
4, the/usr/lpp/db2_07_01/java12 under the Db2java.zip copy to their own Web project under the Web-inf\lib, if the use of Tomcat, the copy of the file renamed to Db2java.jar;
5, on the server, Su-< database instance User name >
Execute DB2JSTRT 6789 (this sentence starts the DB2JD process, 6789 is the default server listens for JDBC2 connection ports, or it can be set to any other conflict-free port. )
6, in the establishment of their own projects, the establishment of a test JSP file, the contents are as follows:
<%@ page contenttype= "text/html; charset=gb2312 "language=" java import= "java.sql.*"%>

<body>
The following is the data read from the DB2 database:<table border=1>
<%
Class.forName ("COM.ibm.db2.jdbc.net.DB2Driver"). newinstance ();
Connection con=java.sql.drivermanager.getconnection ("Jdbc:db2://192.168.168.2:6789/chaodb", "Db2inst1", "Mima");
Statement stmt=con.createstatement ();
ResultSet rst=stmt.executequery ("Select username from Tname");
while (Rst.next ())
{
Out.println ("<tr>");
Out.println ("<td>" +rst.getstring ("username") + "</td>");
Out.println ("</tr>");
}
Closing connections, releasing resources
Rst.close ();
Stmt.close ();
Con.close ();
%>
</table>
</body>

Description
192.168.168.2 is the IP address of the server;
6789 is JDBC2 to listen to the port number, and server-side settings consistent, if the server itself is 6789, then the program of this local reference, you can omit this number.
Chaodb is a database built on the server;
Db2inst1 is an instance user with a CHAODB database;
Mima is the password of the instance user db2inst1;
First in the database to create a table, the name is Tname, which has a column is username, input some data into.



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.