酷文首页  
站内搜索:
网站地图 | RSS订阅 | 收藏本站
经济论文
证券金融
工商管理
会计审计
法学论文
医药论文
社会论文
教育论文
计算机论文
艺术论文
哲学论文
财政税收
财务管理
公共管理
理学论文
政治论文
文学论文
工学论文
文化论文
实用文档
应用文
自考成考
演讲稿
法律文书
子栏目导行↓
网站赞助商↓
本类热点↓
本类更新↓
热门标签↓
网摘收藏↓

基于JAVA的长沙市公交系统乘车指南的设计与实现

作者:郭 程
来源:酷文网
点击:
载入中...
加入时间:2008-08-02
字体大小:[  ]

</data-source>

 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)){


     //如果存在
   result = db.exeUpdate(sql);
  }
  else{
  //如果不存在,则给出错误页面
   msg[0]="label.zhandian_deleteStationNull";
  }  
  
  return result;
 }
 
 //修改站点
 public static int modifyZhanDian(conn_Bus db,String zhandian_old,
   String zhandian_new,String msg[]) throws Exception{
  int result=0;
  String sql="update stationinfo set stationName='"+zhandian_new+"' "
    +"where stationName='"+zhandian_old+"'";
  if(isExistZhangDian(db,zhandian_old) && !isExistZhangDian(db,zhandian_new)){
   result = db.exeUpdate(sql);
  }
  else if(!isExistZhangDian(db,zhandian_old)){
   //要修改的站点不存在,无法进行修改
   msg[0]="label.zhandian_modifyBeforeStationNull";
  }

  else if(isExistZhangDian(db,zhandian_new)){
   //修改后的站点出现重复
   msg[0]="label.zhandian_modifyAfterStationExist";
  }  
  
  return result;
 }
其次,通过在struts-config.xml中配置<data-sources></data-sources>来方便控制层既相应的Action类来得到到DataSource对象。配置如下:
<data-sources>
  <data-source key="db_gongjiaoche" type="org.apache.commons.dbcp.BasicDataSource">
   <set-property property="driverClassName" value="org.gjt.mm.mysql.Driver" />
   <set-property property="url" value="jdbc:mysql://localhost:3306/db_bus" />
   <set-property property="maxActive" value="100"/>
   <set-property property="username" value="root"/>
   <set-property property="password" value="123456"/>
   <set-property property="autoCommit" value="true"/>
  </data-source>
  
  <data-source key="db_renyuan" type="org.apache.commons.dbcp.BasicDataSource">
   <set-property property="driverClassName" value="org.gjt.mm.mysql.Driver" />转贴于 酷文网-论文下载中心 http://www.coolwen.net


共13页: 上一页 [1] [2] [3] [4] [5] [6] [7] [8] 9 [10] [11] [12] [13] 下一页

网摘收藏:
免责声明 | 关于我们 | 广告联系 | 友情链接 | 网站地图 | 共同合作
免费论文 毕业论文 毕业论文范文 酷文网(www.coolwen.net) 版权所有 coolwen.net 2007,All Rights Reserved
E-mail:hui_love#tom.com(为防止垃圾邮件请把#换成@) 点击这里给我发消息 点击这里给我发消息
湘ICP备07003917号