/ / This program uses a class reflection class that can automatically fill the query value into the value object. // This class can see IBM's article: Simplify Struts development .package com.lyjweb.wyhn.common;
Import java.sql. *; import com.lyjweb.common. *; import java.util. *;
Public class fenye {private connection con = NULL; Private string SQL = ""; private string page = "1"; // Current page private INT i_PAGE = 1; // Current page private INT i_PAGE_COUNT = 10; // Each page display Article number private String nextpage, prepage, sumpage, sumcount; private String sql_select, sql_from, sql_where, sql_order; private String sql_pre = ""; private String sql_count = ""; // count (*) statement private ResultSet rst = null; private PreparedStatement Stm = NULL; Private Collection Result_c = NULL; Private String S_NULL = "None"; // / Enter Value // Public Void SetConnection (Connection Con) {this.con = con;
public void setSql (String sql_select, String sql_from, String sql_where, String sql_order) {//this.sql=sql; this.sql_select = sql_select; this.sql_from = sql_from; this.sql_where = sql_where; this.sql_order = sql_order; this .sql_count = "select count (*)" sql_from "" sql_where; this.sql = sql_select "" sql_from "" sql_where "" sql_order;} public void setStm (PreparedStatement stm) {this. STM = STM;} public void setpage (string p) {if (p == null) {this.page = "1"; excitation {p = 1;} else {p = p.trim (); if (p. Equals (")) P =" 1 "; this.page = p; this.i_page = INTEGER.PARSEINT (THIS.PAGE);}} public void setPageCount (int pcount) {this.i_page_count = pcount;}
Public void setsqlpre (string sqlpre) {this.sql_pre = SQLPRE;}
public void setS_null (String s_null) {this.s_null = s_null;} // Return value /// public ResultSet getRst () {return rst;} public String getPage () {return page;} public String getNextPage () {return nextpage ;} public String getPrePage () {return prepage;} public String getSumPage () {return sumpage;} public String getCount () {return sumcount;} public Collection getCollection () {return result_c;} /// private String b_string operation , f_string; private String comsql; private void CountPage () throws Exception {// try {PreparedStatement stm1 = con.prepareStatement (sql_count); ResultSet rst_count = stm1.executeQuery (); rst_count.next (); int i_sum = rst_count.getInt (1); RST_Count.close (); RST_Count = null; stm1.close (); STM1 = NULL;
this.sumcount = String.valueOf (i_sum); int page_all = 0; if (i_sum% i_page_count == 0) {page_all = i_sum / i_page_count;} else {page_all = i_sum / i_page_count 1;} sumpage = String.valueOf ( Page_all); if (i_page> page_all) {i_page = Page_All; Page = String.Valueof (i_page);} else if (i_page <1) {i_page = 1; Page = String.Valueof (i_page);} if (i_page = = Page_All) NextPage = String.Valueof (i_page); else nextpage = string.valueof (i_page 1); if (i_page == 1) prepeage = "1"; else prepage = string.valueof (i_page-1); int f_number = i_page * i_page_count; int b_number = f_number-i_page_count 1; b_string = String.valueOf (b_number); f_string = String.valueOf (f_number); //} catch (Exception e) // {// System.out. Println ("Error In Fenye:" E.TOSTRING ()); //}} Private Void Comsql () {comsql = "from (SELECT ROWNUM ROW_ID, TTTTTT2. * from (" SQL ") TTTT2) Where row_id BetWeen " B_String " AND " f_string; if (SQL_ pre.equals ( "")) comsql = sql_select comsql; else comsql = sql_pre comsql; // return comsql;} private void SearchData () throws Exception {String s = comsql; stm = con.prepareStatement (s); rst = stm.executeQuery (); public int Dofenye () {THIS.COUNTPAGE (); this.COMSQL (); this.searchdata (); return 1;} catch (Exception E) {system.out.println "Error In Fenye:" E.TOString ()); return 0;}}}}}}}}} {try {system.out.println (SQL_COVNT);