(表格1)的内容既是实现的基本算法,对于不同精度要求的用户客户在这里下功夫,实现更高的精度要求。我把算法放在JSP页面的目的是为了适应部分用户可能没有使用JavaBean的习惯或是不打算使用JavaBean作为下一层的对象。但是本文以提供JavaBean作为下一层的对象,实现数据库的连接和访问数据库之类的工作。请参考(表格2)。

PlanManager.Java中的部分代码

privateConnection conn = null; 
        
       
privateStatement st = null; 
       
privateResultSet rs = null; 
       
privatePreparedStatement pstmt = null; 
        
publicboolean UpdatePlan(int type,String proname,String stAllM,String endAllM, 
          
String iAll,String startDate,String endDate) { 
           
String sql = ""; //可实行的SQL语句 
            
this.getConnection();//数据库连接是在另一个地方提供,这里不作详细的描述 
       
//type代表不同类型的-选择调整对象 
      
if (type = = 1) {//根据不同的选择调整对象构着不同的SQL语句 
           
sql = 
      
"update PlanSc set stAllM=" 
     
+ stAllM 
      
+ ",endAllM=" 
      
+ endAllM 
      
+ ",iAll=" 
      
+ iAll 
      
+ ",startdate='" 
      
+ startDate 
      
+ "',endDate='" 
      
+ endDate 
      
+ "' where proname='" 
      
+ proname 
      
+ "'"; 
       
} else { 
      
sql = 
      
"update PlanSc2 set stAllM=" 
     
+ stAllM 
      
+ ",endAllM=" 
      
+ endAllM 
      
+ ",iAll=" 
      
+ iAll 
      
+ ",startdate='" 
      
+ startDate 
      
+ "',endDate='" 
      
+ endDate 
      
+ "' where proname='" 
      
+ proname 
      
+ "'"; 
       
} 
     
boolean f = false; 
       
try { 
     
st = conn.createStatement(); 
       
f = st.execute(sql);//执行SQL语句 
        
} catch (Exception ex) { 
        
ex.printStackTrace(); 
     
}finally { 
       
try { 
     
if (st != null) { 
        
st.close(); 
     
} 
     
if (conn != null) { 
        
conn.close(); 
     
} 
     
dbconn.CloseConn(); 
     
} catch (SQLException ex) { 
        
System.out.print("关闭连接错误"); 
       
} 
     
} 
     
return f;//返回执行的情况 
      
}

(表格2)

接下来我们介绍显示的第一个页面的实现,主要是通过PlanManager.Java从数据库获得数据,之后通过Hashtable(哈希表)+Vector变量传递到JSP页面(jindubiao.jsp),jindubiao.jsp再把传递过来的数据解开,放到数组以便使用。

(表格3)调用PlanManager获得数据

jindubiao.jsp中的部分代码

<jsp:useBean id="planC" class="nsbd.plan.PlanManager"></jsp:useBean>
<%         
       Vector vec = new Vector();
              try{
调用PlanManager获得数据
              }catch(Exception ex){
                     System.out.print(ex.getMessage());
              }
%>

(表格3)