`/ Call the JavaBean output set set through servlet, and print
// javabean: Tbean Sourcecode
Package demo;
Import java.io. *;
Import java.sql. *;
/ **
* Insert the type description here.
* Create date: (00-7-10 8:30:32)
* @Author: administrator
* /
Public Class Tbean Implements Serializable {
Protected connection conn = NULL;
protected statement stmt = null;
protected java.sql.resultset result;
/ **
* TBean structure sub-annotation.
* /
Public tbean () {
Super ();
}
/ **
* Insert the method herein.
* Create date: (00-7-10 8:31:06)
* /
Public void execute () {
Try {
Class.Forname ("com.ibm.db2.jdbc.app.db2driver"). NewInstance ();
CONN = DriverManager.getConnection ("JDBC: DB2: Sample", "DB2Admin", "DB2Admin");
STMT = conn.createstatement ();
String SQL = "SELECT * from Staff Where DEPT = 20"
ResultSet RS = Stmt.executeQuery (SQL);
SETRESULT (RS);
} catch (sqlexception e) {
} catch (IllegaCCssexception E2) {
} catch (classnotfoundexception e3) {
} catch (InstantiationException E4) {
}
}
/ **
* Insert the method herein.
* Create date: (00-7-10 8:36:42)
* @Return java.sql.resultset
* /
Public java.sql.resultset getResult () {
Return Result;
}
/ **
* Insert the method herein.
* Create date: (00-7-10 8:36:42)
* @Param newResult java.sql.resultset
* /
Public void setResult (java.sql.resultset newresult) {
Result = newresult;
}
/ **
* Insert the method herein.
* Create date: (00-7-10 8:35:54)
* /
Public void sqlclose () {
Try {
CONN.CLOSE ();
Stmt.close ();
} catch (sqlexception e) {
}
}
}
// servlet: TSERVLET, call JavaBean, and print the result set:
Package demo;
Import java.io. *;
Import java.sql. *;
Import javax.servlet. *;
Import javax.servlet.http. *;
/ **
* Insert the type description here.
* Create date: (00-7-10 8:37:57)
* @Author: administrator * /
Public Class TSERVLET EXTENDS HTTPSERVLET IMPLEments SerializAble {
/ **
* TSERVLET constructor annotation.
* /
Public TSERVLET () {
Super ();
}
/ **
* Service method annotation.
* /
Public void service (httpservletRequest Req, httpservletResponse res) throws servletexception, oewception {
Try {
Demo.tbean javabean = new demo.tbean ();
Javabean.execute ();
ResultSet RS1 = javabean.getresult ();
PrintWriter out = res. maxwriter ();
Res.SetContentType ("text / html");
Out.println ("