

2,在Action类中使用如下形式得到DataSource
ServletContext context = servlet.getServletContext();
DataSource dataSource = (DataSource)context.getAttribute("db_gongjiaoche");
DataSource dataSource = (DataSource)context.getAttribute("db_renyuan ");
业务方法放在整合在Action类里。能过Action调用相应包内的produce.java内的核心业务处理方法具体实现与数据库进行交互,读取,保存,修改数据库信息。本系统主要根据设计,跟车次相关的核心业务处理方法的具体实现放在车次包的checi_procedure.java中,跟车次相关的核心业务处理方法具体实现放在站台包zhandian_procedure.java中,而与主面相关的业务处理方法的具体实现放在main包中的procedure.java中。
下面是与站台有关操作包中的zhandian_procedure.java核心程序段,
//将站点名取出显示在列表栏中,以字符串的形式
public static String showZhanDianList(Vector resultList){
String result="\n";
stationinfo station=new stationinfo();
for(int i=0;i<resultList.size();i++){
station = (stationinfo)resultList.get(i);
result=result+station.getStationName()+"\n";
}
return result;
}
//查询数据库有此站点
public static boolean isExistZhangDian(conn_Bus db,String zhandian) throws Exception{
boolean result=false;
ResultSet rs=null;
//根据给定的站点名字,建立SQL语句来查询stationinfo表
String sql="select * from stationinfo where stationName='"+zhandian+"'";
//用Database执行sql语句
rs=db.exeQuery(sql);
//判断执行结果是否有数据
if(rs.next()) result=true;
return result;
}
//添加站点
public static int addZhanDian(conn_Bus db,String zhandian,String msg[]) throws Exception{
int result=0;
String sql ="insert into stationinfo(stationName) values('"+zhandian+"')";
if(!isExistZhangDian(db,zhandian)){
result = db.exeUpdate(sql);
}
else{
//插入的站点已经存在
msg[0]="label.zhandian_insertedStationExist"; //字符串数组进行参数传递
}
return result;
}
//删除站点
public static int deleteZhanDian(conn_Bus db,String zhandian,String msg[]) throws Exception{
int result=0;
//通过给定站点来从stationinfo表删除记录
String sql="delete from stationinfo where stationName='"+zhandian+"'";
//先判断stationinfo表中是否具有指定站点的记录
if(isExistZhangDian(db,zhandian)){