test jdbc properties

	public void test()
	{
		//classes\spring\db-config.properties
		/*
		jdbc.driverClassName=oracle.jdbc.driver.OracleDriver
		jdbc.url=jdbc:oracle:thin:@127.0.0.1:1521:zwf
		jdbc.username=11
		jdbc.password=11
		 */
		
		InputStream in = SysApplicationListener.class.getResourceAsStream("/spring/db-config.properties");  
        Properties p = new Properties();  
        try 
        {  
            p.load(in);  
            String driverClassName = p.getProperty("jdbc.driverClassName");
            String url = p.getProperty("jdbc.url");
            String username = p.getProperty("jdbc.username");
            String password = p.getProperty("jdbc.password");
        }
        catch (IOException e) 
        {  
            e.printStackTrace();  
        }
	}




	public void test()
	{
		//classes\spring\db-config.properties
		/*
		jdbc.driverClassName=oracle.jdbc.driver.OracleDriver
		jdbc.url=jdbc:oracle:thin:@127.0.0.1:1521:zwf
		jdbc.username=11
		jdbc.password=11
		 */
        try 
		{
			String path = SysApplicationListener.class.getResource("/spring/db-config.properties").getPath();
			System.out.println(path);
//			InputStream in = SysApplicationListener.class.getResourceAsStream("/spring/db-config.properties");
			InputStream in = new BufferedInputStream(new FileInputStream(path));

			Properties p = new Properties();

			//
			p.load(in);
			in.close();

			//
			String driverClassName = p.getProperty("jdbc.driverClassName");
			String url = p.getProperty("jdbc.url");
			String username = p.getProperty("jdbc.username");
			String password = p.getProperty("jdbc.password");
			String isUpdate = p.getProperty("isUpdate");

			//
			System.out.println(driverClassName);
			System.out.println(url);
			System.out.println(username);
			System.out.println(password);
			System.out.println(isUpdate);

			//
			if (isUpdate != null && isUpdate.equals("0"))
			{
//				String path = SysApplicationListener.class.getResource("/spring/db-config.properties").getPath(); 
				FileOutputStream out = new FileOutputStream(path);
				p.put("isUpdate", "1");
				p.store(out, "so boring. zengwenfeng.update");
				out.close();
				out.flush();

				//
				System.out.println("ok!");
			}
		}
        catch (IOException e) 
        {  
            e.printStackTrace();  
        }
	}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值