跨系统数据库取数实现方案

情景:假如要做一个系统A的报表,但其中部分字段的取值在系统B,那系统A里就不能一个SQL查询系统A和系统B的数据了,这种情况可以系统B提供一个接口,去查询取得系统B的数据。除此之外,还可以用以下方案实现取数:

1.利用url,用户名,密码直接连接系统B的数据库,这些参数可以在系统A的数据库中建一个表来保存,方便后续的修改维护。


2.java连接系统B数据库。

    /**
     * 取得影像系统的数据库连接
     * @return
     */
	public static Connection getImageConnection(Context ctx){
		String driver = null;
		String url = null;
		String username = null;
		String password = null;
		try
		{
			String sql = "select  id,name,driver,imgurl,imgname,imgpassword from imageconparam where id='001'";
			IRowSet rs = DbUtil.executeQuery(ctx, sql);
			if(rs.next())
			{
				driver = rs.getString("driver");
				url = rs.getString("imgurl");;
				username = rs.getString("imgname");;
				password = rs.getString("imgpassword");;
			}
		}
		catch (BOSException e1)
		{
			e1.printStackTrace();
		}
		catch (SQLException e)
		{
			e.printStackTrace();
		}
		
		Connection imageConnection = null;
		try
		{
			Class.forName(driver);
			imageConnection= DriverManager.getConnection(url, username, password);
		}
		catch (ClassNotFoundException e2)
		{
			e2.printStackTrace();
		}
		catch (SQLException e)
		{
			e.printStackTrace();
		}
		return imageConnection;
	}

3.查询系统B数据并返回结果。

	/**
	 * 从影像系统取得后补发票影像号对应的接收时间
	 * @param imagenoList
	 * @return
	 */
	private Map<String, String> getArchiveDate(List<String> imagenoList)
	{
		Map<String,String> archivedateMap = new HashMap<String, String>();
		try
		{
			String inparam = ToolUtils.aryToStr(imagenoList);
			Context ctx = WafContext.getInstance().getContext();
			Connection imageConnection = BDUtil.getImageConnection(ctx);
			Statement statementimg = imageConnection.createStatement();
			String sql = "select 1,2 from t_hist_task where rownum <=10";
			ResultSet rs = statementimg.executeQuery(sql);
			while(rs.next())
			{
				String imgeno = rs.getString(1);
				String date = rs.getString(2);
				if(!StringUtils.isEmpty(imgeno) && !StringUtils.isEmpty(date))
				{
					archivedateMap.put(imgeno, date);
				}
			}
		}
		catch (SQLException e1)
		{
			e1.printStackTrace();
		}

		return archivedateMap;
	}


  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值