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

📄 roledaoimpl.java

📁 基于Java的地图数据管理软件。使用MySQL数据库管理系统。
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
			while (rs.next()) {
				townCode = rs.getString("townCode");
				rowCount = rs.getRow();
			}
			rs.close();
			if (rowCount !=0)
				return townCode;
				else return null;
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			dbo.close();
		}
		return null;
	}

	public String getCountyCode(String countyName) {
		DBOperator dbo = new DBOperator();
		String townCode = "";
		try {
			String sqlStr = "select countyCode from tt_county where countyName like '%" + countyName + "%'";
			//System.out.println(sqlStr);
			dbo.setPrepareStatement(sqlStr);
			ResultSet rs = dbo.executeQuery();
			while (rs.next()) {
				townCode = rs.getString("countyCode");
			}
			rs.close();
			return townCode;
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			dbo.close();
		}
		return townCode;
	}

	public boolean addVillage(String villageCode, String villageName) {
		DBOperator dbo = new DBOperator();
		String query = "insert into tt_village(villageCode,villageName) values ('" + villageCode + "','" + villageName + "')";
		try {
			System.out.println(query);
			dbo.setPrepareStatement(query);
			dbo.executeUpdate();
			return true;
		} catch (Exception e) {
		} finally {
			dbo.close();
		}
		return false;
	}

	public String getVillageCode(String villageName, String code) {
		DBOperator dbo = new DBOperator();
		String townCode = "";
		String cunName = "";
		int rowCount = 0;
		if (villageName.indexOf("支部") >-1 || villageName.indexOf("村支")> -1){
			cunName = villageName.substring(0,villageName.length()-2);
			System.out.println("======"+ cunName);
			villageName = cunName;
		}else if (villageName.indexOf("行政村") > -1 || villageName.indexOf("居委会") > -1){
			cunName = villageName.substring(0,villageName.length()-3);
			System.out.println("======"+ cunName);
			villageName = cunName;
		}else if (villageName.indexOf("村部") > -1 || villageName.indexOf("村委") > -1){
			cunName = villageName.substring(0,villageName.length()-2);
			System.out.println("======"+ cunName);
			villageName = cunName;
		}
		try {
			String sqlStr = "select villageCode from tt_village where villageName like '%" + villageName + "%' and left(villageCode,6)='" + code +  "'";
			System.out.println(sqlStr);
			dbo.setPrepareStatement(sqlStr);
			ResultSet rs = dbo.executeQuery();
			while (rs.next()) {
				townCode = rs.getString("villageCode");
				rowCount = rs.getRow();
			}
			rs.close();
			if (rowCount !=0)
			return townCode;
			else return null;
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			dbo.close();
		}
		return null;
	}

	public String getTownName(String townCode) {
		DBOperator dbo = new DBOperator();
		String townName = "";
		try {
			String sqlStr = "select townName from tt_town where townCode like '%" + townCode + "%'";
			System.out.println(sqlStr);
			dbo.setPrepareStatement(sqlStr);
			ResultSet rs = dbo.executeQuery();
			while (rs.next()) {
				townName = rs.getString("townName");
			}
			rs.close();
			return townName;
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			dbo.close();
		}
		return townName;
	}

	public String getCountyCode2(String countyName, String code) {
		DBOperator dbo = new DBOperator();
		String townCode = "";
		try {
			String sqlStr = "select countyCode from tt_county where countyName ='市辖区' and left(countyCode,4)='" + code +  "'";
			//System.out.println(sqlStr);
			dbo.setPrepareStatement(sqlStr);
			ResultSet rs = dbo.executeQuery();
			while (rs.next()) {
				townCode = rs.getString("countyCode");
			}
			rs.close();
			return townCode;
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			dbo.close();
		}
		return townCode;
	}

	public List getAllCountyList() {
		DBOperator dbo = new DBOperator();
		List countyList = new ArrayList();
		try {
			String sqlStr = "select * from tt_county ";
			System.out.println(sqlStr);
			dbo.setPrepareStatement(sqlStr);
			ResultSet rs = dbo.executeQuery();
			while (rs.next()) {
				County county = new County();
				county.setCountyCode(rs.getString("countyCode"));
				county.setCountyName(rs.getString("countyName"));
				countyList.add(county);
			}
			rs.close();
			return countyList;
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			dbo.close();
		}
		return countyList;
	}

	public List getTownListByCode(String countyCode) {
		DBOperator dbo = new DBOperator();
		List townList = new ArrayList();
		try {
			String sqlStr = "select * from tt_town where left(townCode,6)= '" + countyCode + "'";
			System.out.println(sqlStr);
			dbo.setPrepareStatement(sqlStr);
			ResultSet rs = dbo.executeQuery();
			while (rs.next()) {
				Town town = new Town();
				town.setTownCode(rs.getString("townCode"));
				town.setTownName(rs.getString("townName"));
				townList.add(town);
			}
			rs.close();
			return townList;
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			dbo.close();
		}
		return townList;
	}

	public RoleInfo getRoleInfoById(int roleId) {
		DBOperator dbo = new DBOperator();
		RoleInfo ri = new RoleInfo();
		try {
			String sqlStr = "select * from tt_role where roleid= " + roleId;
			System.out.println(sqlStr);
			dbo.setPrepareStatement(sqlStr);
			ResultSet rs = dbo.executeQuery();
			while (rs.next()) {
			
				ri.setRoleName(rs.getString("roleName"));
				ri.setRoleId(rs.getInt("roleId"));
				ri.setPrivilege(rs.getString("privilege"));
				ri.setCreateTime(rs.getDate("createtime"));
				
			}
			rs.close();
			//CurrentUser.saveLog(sqlStr); //保存当前用户操作记录
			return ri;
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			dbo.close();
		}
		return null;
	}

	public boolean updateRoleInfo(String privil ,int roleId) {
		DBOperator dbo = new DBOperator();
		String query = " update tt_role set privilege = '" + privil + "',modifiedTime =";
		          query += "curdate() where roleId = " + roleId;
		try {
			System.out.println(query);
			dbo.setPrepareStatement(query);
			dbo.executeUpdate();
			CurrentUser.saveLog(query); //保存当前用户操作记录
			return true;
		} catch (Exception e) {
		} finally {
			dbo.close();
		}
		return false;
	}

	public List getTownListByAll(String code) {
		DBOperator dbo = new DBOperator();
		List planList = new ArrayList();
	
		try {
			String sqlStr = "select planid,plantype,roadName,townsId,villageName,townName from tt_plandetail " +
					"where planType<3  ";
			      sqlStr += " and townsid like '%" + code +"%' group by townName order by plantype asc ,townsid asc" ;
			System.out.println(sqlStr);
			dbo.setPrepareStatement(sqlStr);
			ResultSet rs = dbo.executeQuery();
			while (rs.next()) {
				PlanDetail pd = new PlanDetail();
			    pd.setPlanId(rs.getInt("planId"));
			    pd.setPlanType(rs.getInt("planType"));
			    pd.setRoadName(rs.getString("roadName"));
			    pd.setTownsId(rs.getString("townsId"));
			    String cityCode = rs.getString("townsId").substring(0,4)+"00000000";
			    String countyCode = rs.getString("townsId");
			    String cityName = City.getCityNameByNum(cityCode);
			    String countyName = City.getCountyName(countyCode);
			    pd.setCityName(cityName);
			    pd.setCountyName(countyName);
			
			    pd.setVillageName(rs.getString("villageName"));
			    pd.setTownName(rs.getString("townName"));
			    planList.add(pd);
			}
			rs.close();
			//CurrentUser.saveLog(sqlStr); //保存当前用户操作记录
			return planList;
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			dbo.close();
		}
		return null;
	}

	public List getVillageListByCode(String code) {
		DBOperator dbo = new DBOperator();
		List countyList = new ArrayList();
		try {
			String sqlStr = "select * from tt_village where villageCode like '%" + code + "%'";
			//System.out.println(sqlStr);
			dbo.setPrepareStatement(sqlStr);
			ResultSet rs = dbo.executeQuery();
			while (rs.next()) {
				Village village = new Village();
				village.setVillageCode(rs.getString("villageCode"));
				village.setVillageName(rs.getString("villageName"));
				countyList.add(village);
			}
			rs.close();
			return countyList;
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			dbo.close();
		}
		return countyList;
	}
	

}


⌨️ 快捷键说明

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