ITPub博客

首页 > Linux操作系统 > Linux操作系统 > temp2

temp2

原创 Linux操作系统 作者:wgf19830218 时间:2011-05-05 19:05:13 0 删除 编辑

right.jsp


<%@ page language="java" import="java.util.*,com.wgf.*" pageEncoding="BIG5"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>



 
   
   
    test
 
 
 
 
 
 


 <%
 GoodBeanDeal gbd = new GoodBeanDeal();
  int pageNow=1;
  //int pageSize=6;
  int k=0;
  ArrayList al = new ArrayList();
  try{
  String s_pageNow = (String)request.getAttribute("pageNow");
  //String s_pageSize = (String)request.getAttribute("pageSize");
  if(s_pageNow!=null){
  pageNow = Integer.parseInt(s_pageNow);
  }
  }
  catch(Exception e){
  e.printStackTrace();
  }
  if(pageNow==1){
  al = gbd.getDisplayContent(pageNow);
  }
  else{
  al = (ArrayList)request.getAttribute("ArrayList");
  }  
  %>       
  
 
 

    <%for(int j=0;j<2;j++){ %>
   
   
     
        <%
  for(int i=0;i<3;i++){
  if(k>=al.size()){
   break;
   }
  GoodsBean gb = (GoodsBean)al.get(k);       
  %>
       
       
       
       
        <%
        if(j==0){
         %>
 
   
 
  <%} %>
  <%} %>
 

       
         
           
            <%=gb.getGOODSNAME() %>
         

         
            <%=gb.getGOODSPRICE() %>
         

         
            <%=gb.getGOODSPUBLISHER() %>
         

         
           
           
       
<%=gb.getGOODSINTRO() %>
<%
        k++;
        } %>
<%
  for(int x=1;x<3;x++){
  out.print("["+x+"]   ");
  }
   %>
  


 

 


GoodsBeanDeal

package com.wgf;

import java.sql.*;
import java.util.*;
import com.wgf.*;

public class GoodBeanDeal {
 Connection con = null;
 Statement ps = null;
 ResultSet rs = null;
 int pageSize=6; //每頁多少條記錄
 int pageNow=0; //當前是多少頁
 int pageCount=0;//一共分幾頁
 int totalCount=0;//總記錄數
 
 
 public int getpageCount(){
  con = new ConnectDB().getConnectDB();
  //獲取在顯示內容的條數
  String sql = "select  count(*)  from ptc.USER_INFORMATION";
  try {
   ps = con.prepareStatement(sql);
   rs = ps.executeQuery(sql);
   if(rs.next()){
    totalCount = rs.getInt(1);
   }
   
  } catch (Exception e) {
   e.printStackTrace();
  }
  //計算pageCount(一共多少頁)
  if(totalCount%pageSize==0){
   pageCount = totalCount/pageSize;
  }
  else{
   pageCount = totalCount/pageSize+1;
  }
  return pageCount;
 }
 
 
 public int gettotalCount(){
  con = new ConnectDB().getConnectDB();
  //獲取在顯示內容的條數
  String sql = "select  count(*)  from ptc.USER_INFORMATION";
  int totalCount=0;
  try {
   ps = con.prepareStatement(sql);
   rs = ps.executeQuery(sql);
   if(rs.next()){
    totalCount = rs.getInt(1);
   }
   
  } catch (Exception e) {
   e.printStackTrace();
  }
  //計算pageCount(一共多少頁)
  return totalCount;
 }
 
 
 
 public ArrayList getDisplayContent(int pageNow){
  ArrayList contentArrayList = new ArrayList();
  ConnectDB cdb = new ConnectDB();
  GoodsBean gb = null;
  int totalCount = new GoodBeanDeal().gettotalCount();
  con = cdb.getConnectDB();
  
  String sqlContent =  "select  * from ptc.goods where  rownum<="
   + pageSize
   + " and goodsname not in(select  goodsname from ptc.goods where rownum<="
   + (pageNow - 1) * pageSize + ")";
  System.out.println(sqlContent);
  try {
   ps = con.prepareStatement(sqlContent);
   rs = ps.executeQuery(sqlContent);
   while(rs.next()){
    gb = new GoodsBean();
    gb.setGOODSID(rs.getInt(1));
    gb.setGOODSNAME(rs.getString(2));
    gb.setGOODSINTRO(rs.getString(3));
    gb.setGOODSPRICE(rs.getFloat(4));
    gb.setGOODSNUM(rs.getInt(5));
    gb.setGOODSPUBLISHER(rs.getString(6));
    gb.setPHOTONAME(rs.getString(7));
    gb.setGOODSTYPE(rs.getString(8));
    contentArrayList.add(gb);
   }
  } catch (Exception e) {
   e.printStackTrace();
  }
  int addEmptyNum=totalCount%pageSize;
  try{
  for(int i=0;i   gb = new GoodsBean();
   gb.setGOODSID(0);
   gb.setGOODSNAME("無信息");
   gb.setGOODSINTRO("無信息");
   gb.setGOODSPRICE(0);
   gb.setGOODSNUM(0);
   gb.setGOODSPUBLISHER("無信息");
   gb.setPHOTONAME("noimage.jpg");
   gb.setGOODSTYPE("無信息");
   contentArrayList.add(gb);
  }
  }
  catch(Exception e){
   e.printStackTrace();
  }
  return contentArrayList;
 }
 
 public GoodsBean getGoodsByID(int goodsID){
  GoodsBean gb = null;
  con = new ConnectDB().getConnectDB();
  String sql = "select  *  from ptc.goods where goodsID='"+goodsID+"'";
  try {
   ps = con.prepareStatement(sql);
   rs = ps.executeQuery(sql);
   while(rs.next()){
    gb = new GoodsBean();
    gb.setGOODSID(rs.getInt(1));
    gb.setGOODSNAME(rs.getString(2));
    gb.setGOODSINTRO(rs.getString(3));
    gb.setGOODSPRICE(rs.getFloat(4));
    gb.setGOODSNUM(rs.getInt(5));
    gb.setGOODSPUBLISHER(rs.getString(6));
    gb.setPHOTONAME(rs.getString(7));
    gb.setGOODSTYPE(rs.getString(8));
   }
   
  } catch (Exception e) {
   e.printStackTrace();
  }
  
  return gb;
 }
 public ArrayList getGoodsContent(){
  ArrayList al = new ArrayList();
  con = new ConnectDB().getConnectDB();
  String sql = "select  *  from ptc.goods";
  GoodsBean gb = null;
  try {
   
   ps = con.prepareStatement(sql);
   rs = ps.executeQuery(sql);
   while(rs.next()){
    gb = new GoodsBean();
    gb.setGOODSID(rs.getInt(1));
    gb.setGOODSNAME(rs.getString(2));
    gb.setGOODSINTRO(rs.getString(3));
    gb.setGOODSPRICE(rs.getFloat(4));
    gb.setGOODSNUM(rs.getInt(5));
    gb.setGOODSPUBLISHER(rs.getString(6));
    gb.setPHOTONAME(rs.getString(7));
    gb.setGOODSTYPE(rs.getString(8));
    al.add(gb);
   }
   
  } catch (Exception e) {
   e.printStackTrace();
  }
  return al;
 }
}

 

 

ConnectDB

package com.wgf;
import java.sql.*;

public class ConnectDB {
 public Connection getConnectDB() {
  Connection con = null;
  try {
   Class.forName("oracle.jdbc.driver.OracleDriver");
  } catch (Exception e) {
   e.printStackTrace();
  }
  try {
   con = DriverManager.getConnection("jdbc:oracle:thin:@10.142.252.132:1521:mesdev","ptc","ptc");
   //con = DriverManager.getConnection("jdbc:oracle:thin:@10.142.252.132:1521:mesdev", "ptc","ptc");
  } catch (SQLException e) {
   e.printStackTrace();
  }
  return con;
 }
}

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/22453766/viewspace-694547/,如需转载,请注明出处,否则将追究法律责任。

上一篇: temptoday
下一篇: temp3
请登录后发表评论 登录
全部评论

注册时间:2009-09-01

  • 博文量
    38
  • 访问量
    45608