Servlet call javabean output result set example

zhaozj2021-02-12  144

Servlet calls JavaBean output result sets `// Call the JavaBean output set set through servlet, and print // javabean: Tbean SourcecodePackage Demo; import java.io. *; Import java.sql. *; / *** Insert here Type Description. * Date Created: (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 method description here. * 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 (IllegalaccessExcection E2) {} catch (ClassNotFoundException E3) {} catch (instantiationException E4) {}} / *** Insert method description here. * Creation date: (00-7-10 8:36:42) * @Return java.sql.resultset * / public java.sql.resultset getResult () {return result;} / *** Insert method here . * Creation date: (00-7-10 8:36:42) * @Param newResult java.sql.resultset * / public void setResult (java.sql.resultset newResult) {result = newResult;} / *** here Insert method illustration. * Creation date: (00-7-10 8:35:54) * / public void sqlclose () {Try {conn.close (); stmt.close ();} catch (sqlexception e) {}}} // Servlet: tservlet, call JavaBean, 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 a date: (00-7-10 8:37:57) * @Author: administrator * / public class tservlet Extends httpservlet imports serializable {/ *** TSERVLET constructor.

转载请注明原文地址:https://www.9cbs.com/read-6400.html

New Post(0)