⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 countrymanager.java

📁 eclipse java/jsp 航空管理系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
			return b;
		} catch (SQLException e) {
			
			AppMode.loginoutUser();
			
			b = false;
			System.out.print("操作失败");
			return b;
		}
	}

	/*
	 * name:         排序
	 * describing:   按照国家或城市排序
	 * @param        CountryManagerForm cmf
	 * @return       StringBuffer buffer 返回按照国家或城市排序好的表
	 *               两种情况:按照国家排序和按照城市排序
	 */
	public StringBuffer countryAndCitySelect(CountryManagerForm cmf) {
		
		AppMode.registerUser();

		Statement sql = null;
		ResultSet rs = null;
		CountryManagerForm countryManagerform = cmf;
		String selectmethod;
		selectmethod = countryManagerform.getSelectmethod();
		selectmethod = change(selectmethod);
		StringBuffer buffer = new StringBuffer();

		try {
			db=new DbConnection();
            con=db.getCon();
			sql = con.createStatement();
			buffer.append("<Table Border>");
			buffer.append("<tr>");
			buffer.append("<TH width=100>"+"国家");
			buffer.append("<TH width=100>"+"城市");
			buffer.append("</tr>");
			if (selectmethod.equals("国家排序")) {
				rs = sql.executeQuery("select * from country " 
                                      +"order by countryname");
				while (rs.next()) {
					buffer.append("<tr>");
					buffer.append("<td >" + rs.getString(2) + "</td>");
					buffer.append("<td >" + rs.getString(3) + "</td>");
					buffer.append("<td><input type=\"radio\" " 
                                 +"name=\"no\" value=\""
							     + rs.getInt(1) + "\"></td>");
					buffer.append("</tr>");
				}
				buffer.append("</Table>");
				con.close();
                db.d_close();
                
                AppMode.loginoutUser();
            
                
				return buffer;
			} else if (selectmethod.equals("城市排序")) {
				rs = sql.executeQuery("select * from country " 
                                     +"order by cityname");
				while (rs.next()) {
					buffer.append("<tr>");
					buffer.append("<td >" + rs.getString(2) + "</td>");
					buffer.append("<td >" + rs.getString(3) + "</td>");
					buffer.append("<td><input type=\"radio\" " 
                                 +"name=\"no\" value=\""
							     + rs.getInt(1) + "\"></td>");
					buffer.append("</tr>");
				}
				buffer.append("</Table>");
				con.close();
                db.d_close();
                
                AppMode.loginoutUser();
                
                
				return buffer;
			} else{
				
				AppMode.loginoutUser();
				return buffer;
			}
				
		}

		catch (Exception e) {
			
			AppMode.loginoutUser();
			
			return new StringBuffer("无法建立连接");
		}
	}

	/*
	 * name:         一览页面中的国家与城市信息删除
	 * describing:   VIEW页中删除country表中的国家和城市信息
	 * @param        CountryManagerForm cmf
	 * @return       boolean b 判断是否对数据库修改成功
	 *               (有待改进,返回类型最好为int型可以时间多种异常跳转)
	 */
	public boolean ViewDelete(CountryManagerForm cmf) {
		
		AppMode.registerUser();

		/*获得FORM里的参数*/
		CountryManagerForm countrymanagerform = cmf;
		boolean b = true;
		Statement sql = null;
		ResultSet rs = null;
		String no = null;
		no = countrymanagerform.getNo();
		System.out.println(no);
		int nono = Integer.parseInt(no);
		try {
			db=new DbConnection();
            con=db.getCon();
			sql = con.createStatement();
			if (nono != 0) {
				String condition = "delete from country where no=" + nono;
				sql.executeUpdate(condition);
				con.close();
                db.d_close();
                
                AppMode.loginoutUser();
              
                
				return b;
			} else{
				con.close();
                db.d_close();
                
                AppMode.loginoutUser();
                
                
                return b = false;
              }
		} catch (SQLException e) {
			
			AppMode.loginoutUser();
			
			b = false;
			System.out.print("操作失败");
			return b;
		}
	}

	/*
	 * name:         一览页面中查询出的结果的锁定的信息内容
	 * describing:   查询出一览页面中锁定的国家和城市名称还有NO,用来在修改的时候调用
	 * @param        CountryManagerForm cmf
	 * @return       str[2] 返回锁定的国家和城市名称
	 *               为了把锁定的国家和城市姓名返回到modify页面上
	 */
	public String[] ModifyView(CountryManagerForm cmf) {
		
		AppMode.registerUser();

		/*获得FORM里的参数*/
		CountryManagerForm countrymanagerform = cmf;
		Statement sql = null;
		ResultSet rs = null;
		String no = null;
		no = countrymanagerform.getNo();
		//System.out.println(no);
		int nono = Integer.parseInt(no);
		String str[] = { "null", "null" };
		try {
			db=new DbConnection();
            con=db.getCon();
			sql = con.createStatement();
			/*如果选中城市的话把城市名和国家名放入数组当中去*/
			String condition = "select * from country where no=" + nono;
			rs = sql.executeQuery(condition);
			rs.first();
			String countryname = rs.getString(2);
			str[0] = countryname;
			String cityname = rs.getString(3);
			str[1] = cityname;
			con.close();
            db.d_close();
            
            AppMode.loginoutUser();
            
			return str;
		} catch (SQLException e) {
			
			AppMode.loginoutUser();
			
			System.out.print("操作失败");
			return str;
		}

	}

	/*
	 * name:         国家与城市信息修改
	 * describing:   修改country表中的国家和城市信息
	 * @param        CountryManagerForm cmf
	 * @return       info 根据info值的不同实现不同页面的跳转
	 */
	public int countryAndCityModify(CountryManagerForm cmf) {
		
		AppMode.registerUser();

		/*获得FORM里的参数*/
		CountryManagerForm countrymanagerform = cmf;
		/*根据info的返回值做不同页的跳转*/
		int info;
		Statement sql = null;
		ResultSet rs = null;
		String cityname;
		String no;
		String countryname;
		no = countrymanagerform.getNo();
		int nono = Integer.parseInt(no);
		cityname = countrymanagerform.getCityname();
		cityname = change(cityname);
		countryname = countrymanagerform.getCountryname();
		countryname = change(countryname);
		String tempcityname = null;
		System.out.println(no);
		System.out.println(cityname);
		System.out.println(countryname);
		try {
			db=new DbConnection();
            con=db.getCon();
			sql = con.createStatement();
			rs = sql.executeQuery("SELECT cityname "
                                  +"from country where cityname="
							      + "'" + cityname + "'");
			/*int getRow()得到当前的行号,如果结果集没有行,返回0。如不判断将返回SQL异常*/
			rs.last();
			int i = rs.getRow();
			System.out.println(i);
			if (rs.getRow() != 0) {
				rs.first();
				tempcityname = rs.getString(1);
			} else {
				tempcityname = "null";
			}
			String condition = "update country set countryname=" + "'"
					           + countryname + "'" + "," 
                               + "cityname=" + "'" 
                               + cityname+ "'" + "," 
                               + "insert_date=" + "'" 
                               + insert_date + "'"+ "," 
                               + "insert_user_id='kangyi'" + "," 
                               + "update_date="+ "'" 
                               + update_date + "'" + "," 
                               + "update_user_id='kangyi'"
					           + "where no=" + no;
			/*如果在一览页返回的NO 为00则证明用户没有选择国家和城市,返回出错信息为您没有选中*/
			if (!cityname.equals(tempcityname)) {
                sql.executeUpdate(condition);
                con.close();
                db.d_close();
                
                AppMode.loginoutUser();
                
                return info=1;
			} else {
				/*回馈给客户的语句为“您输入的城市数据库中已经存在或没有选中国家和城市信息*/
                info = 2;
                con.close();
                db.d_close();
                
                AppMode.loginoutUser();
                
                return info;
			}
		} catch (SQLException e) {
			
			AppMode.loginoutUser();
			
			info = 7;
			System.out.print("操作失败");
			return info;
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -