Appendix B. Java code relating to DB2
This appendix provides the code listings of the DB2 related Java codes.
B.1 Java servlet TestDB2
package penguins.access.db2;
import java.sql.*;
import javax.servlet.http.*;
import javax.servlet.*;
public class TestDB2 extends HttpServlet {
static {
try {
Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");
} catch (Exception e) {
e.printStackTrace();
}
}
public TestDB2() {
super();
}
public void doGet(HttpServletRequest req, HttpServletResponse res) {
try {
String url = "jdbc:db2:sample";
String uid = "db2inst1";
String pwd = "ibmdb2";
Connection con = DriverManager.getConnection(url, uid, pwd);
ServletOutputStream out = res.getOutputStream();
res.setContentType("text/html");
out.print("TestDB2

");

out.print("select * from department

");

Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select * from department");
while (rs.next()) {
out.print(rs.getString(1) + ":" + rs.getString(2) + "

");

}
out.print("");
} catch (Exception e) {
e.printStackTrace();
}
}
}
B.2 Java servlet AccessUserstuf
package penguins.access.db2;
import com.sun.server.http.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.sql.*;
/**
  Copyright IBM Corp. 2000
147




  

Home

About Services Network Support FAQ Order Contact
 

Linux Web Hosting

Our partners:Jsp Web Hosting Unlimited Web Hosting Cheapest Web Hosting  Java Web Hosting Web Templates Best Web Templates PHP Mysql Web Hosting Interland Web Hosting Cheap Web Hosting PHP Web Hosting Tomcat Web Hosting Quality Web Hosting Best Web Hosting  Mac Web Hosting 

Lunarwebhost.net  Business web hosting division of Vision Web Hosting Inc. All rights reserved