必須先下載jt400.jar放在tomcat目錄下的lib之後,重新啟動tomcat才有辦法使用喔

--------------------------------------------------------searchdata.jsp--------------------------------------------------

<%@ page contentType="text/html; charset=big5" language="java" import="java.sql.*" errorPage="" %>

http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

http://www.w3.org/1999/xhtml">





查詢資料












--------------------------------------------------------------------------------------------



---------------------------------------------------------bypage.jsp---------------------------------------------

<%@ page contentType="text/html; charset=big5" import="java.sql.*" %>

<%!

int intPageNo, TotalPage;

int i = 0, intPos = 0;

int cntPageSize = 10;   //一頁10筆

String library_name="";

String member_name="";


private String Show_Result(ResultSet rs) {

  String final_str = "";

  int k = 0, intNo = 0;

  i = 0;

  try {

     while (rs.next()) {

        if (i == 0) {

           ResultSetMetaData rsmd = rs.getMetaData();

           k = rsmd.getColumnCount();  //取得欄位總數

           final_str = "

" +

                       "" +

                       "";

           //--- 顯示欄位名稱 ---

           for (intNo = 1; intNo <= k; intNo++) {

             final_str += "";

           }

           final_str += "";

        }

        //--- get field content ---

        if ((i + 1) <= cntPageSize) {  //考慮PageSize的限制

           final_str += "";

           for (intNo = 1; intNo <= k; intNo++) {

             final_str += "";

           }

           final_str += "";

        } else {

           break;  //exit loop

        }

        //---

        i++;

     }

     final_str += "
No." + rsmd.getColumnName(intNo) + "
" + (intPos + i + 1) + "" + rs.getString(intNo) + "
";

  } catch (SQLException sqle) {

     final_str = "Error occurred: " + sqle + "
";

  }

 

  return final_str;

}

private String Display_Button() {

  String final_str = "";

  if (intPageNo > 1) {

     final_str = "" +

                 "
                 " alt='最前頁'>
" +

                 "" +

                 "
                 " alt='上一頁'>
";

  }

  if (intPageNo < TotalPage) {

     final_str += ""  +

                 "
                 " alt='下一頁'>
" +

                 "" +

                 "
                 " alt='最末頁'>
";

  }

  final_str += "
";

 

  return final_str;

}

%>



分頁控制







分頁控制 (機台最新狀況)





<%

  //********** Output_Page from here **********

  String JDBCDriver = "com.ibm.as400.access.AS400JDBCDriver";

 

  String strSQL = "";

  Connection con = null;

  ResultSet rs = null;

  int intNo = 1;


  strSQL="select * from "+

     request.getParameter("library_name") + "." +

    request.getParameter("member_name") +

    "  ";

   out.println("queryString():"+ request.getQueryString()+"
");

   out.println("SQL查詢語法:" + strSQL + "
");

  // 1.載入JDBC驅動程式

  Class.forName(JDBCDriver);

  // 2.透過DriverManager類別建立Connection物件

 String url="jdbc:as400://192.66.12.2/";                        //jdbc:as400://as400主機ip/

 String id="dp12";                                                                //登入5250的user

 String pwd="dp12";                                                           //登入5250的passwd

 con= DriverManager.getConnection(url,id,pwd);

  // 3.透過Connection物件建立Statement物件

  Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,

                   ResultSet.CONCUR_UPDATABLE);

  //--- 執行SQL指令,並將結果儲存於ResultSet中 ---

  rs = stmt.executeQuery(strSQL);

 


  //--- Process Recordset ---

  //rs.last();  //移到最後一筆

  while(rs.next())

   intNo++;

  out.println("總筆數:" + intNo+"
");

   cntPageSize = Integer.parseInt(request.getParameter("page_count"));

   library_name=request.getParameter("library_name");

   member_name=request.getParameter("member_name");

  //intNo = rs.getRow();  //取得列號,即總筆數

  //out.println("Total record = " + intNo + "
");

  if (intNo > 0) {  //records found

     if ((intNo % cntPageSize) == 0)

        TotalPage = (intNo / cntPageSize);

     else

        TotalPage = (intNo / cntPageSize) + 1;

     //out.println("Total pages = " + TotalPage + "
");

  

     //--- read the value of the page reqested ---

     String strNo;

     if ((request.getParameter("PageNo") == null) ||

         (request.getParameter("PageNo") == ""))

        strNo = "1";

     else

        strNo = request.getParameter("PageNo");

  

     intPageNo = Integer.parseInt(strNo);

     //--- 如果超出最後一頁 ---

     if (intPageNo > TotalPage)

        intPageNo = TotalPage;

  

     //--- Display current page and total pages ---

     out.println("");

     out.println("頁次: " + intPageNo + "");

     out.println(" 總頁次: " + TotalPage);

     out.println("

");

     //--- locate current record ---

     intPos = cntPageSize * (intPageNo - 1);

     //移到符合條件的第一筆記錄之前

     if (intPos == 0)

        rs.beforeFirst();

     else

        rs.absolute(intPos);

    

     //--- Show_Result from here ---

     out.println(Show_Result(rs));


     out.println("


");

     //--- Show_Result end here ---

  }

  //--- 關閉ResultSet物件

  if (rs != null) rs.close();

  //--- 關閉Connection物件

  if (con != null) con.close();

  //********** Output_Page end here **********

  out.println(Display_Button());

%>

remoteAddr:<%=request.getRemoteAddr() %>

ServerName:<%=request.getServerName() %>





----------------------------------------------------------------------------------------------------------------------------------

狼翔月影 發表在 痞客邦 PIXNET 留言(0) 人氣()