The DB2 tutorial you are looking at is: How JSP connects to the DB2 database. JSP and DB2 database links to a lot of information on the Internet, but the author found that most of the data are wrong, can not really deal with the problem of DB2 links, the author after the study to solve this problem, I have a little experience published, and June share.
<%@ page session= "false"%>
<%@ page import= "java.sql.*"%>
<%@ page import= "java.util.*"%>
<body>
<%
String url= "Jdbc:db2:ch"; This format is JDBC: Child protocol: Child name, where CH is the database name
String user= "Db2inst1"; Database Connector ID
String password= "Db2inst1"; Database Connector Password
Drivermanager.registerdriver (New COM.ibm.db2.jdbc.app.DB2Driver ());
The most critical of this, DB2 and Oracle, it is best to create a drive instance explicitly and register it with the drive manager.
Other databases generally use Class.forName ("xxxxxxxxxxx");
Connection Conn=null;
try{
conn= drivermanager.getconnection (Url,user,password);
Statement stmt=conn.createstatement (); To create a database connection object
String sql= "SELECT * from Task";
ResultSet rs=stmt.executequery (SQL);
%>
<table border=1 cellspacing=1 cellpadding=0
<%
while (Rs.next ()) {//Determine whether the end of the recordset
%>
<tr>
<td> <%=rs.getstring (1)%> </td>//Remove the value of each column and display
<td> <%=rs.getstring (2)%> </td>
<td> <%=rs.getstring (3)%> </td>
<td> <%=rs.getstring (4)%> </td>
<td> <%=rs.getstring (5)%> </td>
<td> <%=rs.getstring (6)%> </td>
</tr>
<%}
Rs.close ();
Rs=null;
Stmt.close ();
Stmt=null;
}
finally{///No matter if there is an error, always close the link
if (conn!=null) {
Conn.close ();
}
}
%>
</table>
<body>
The above program runs on the aix4.3+db27.2+jdk1.3+tomcat4.1.6.
<