使用Java在Web上实现简易干特图之四

王朝java/jsp·作者佚名  2006-01-09
宽屏版  字体: |||超大  

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

PlanManager.java中的部分代码

private Connection conn = null;

private Statement st = null;

private ResultSet rs = null;

private PreparedStatement pstmt = null;

public boolean 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{

vec = planC.getAllPlan();//调用PlanManager获得数据

}catch(Exception ex){

System.out.print(ex.getMessage());

}

%>

(表格3)

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有