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-inflib, 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 the port number on which JDBC2 listens. With server-side settings consistent, if the server itself is 6789, then the program of this place 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 set up a table in the database, the name is Tname, and one of the columns is username, input some data into it.