test jdbc properties

来源:互联网 发布:c语言主函数的格式 编辑:程序博客网 时间:2024/05/16 11:34
public void test(){//classes\spring\db-config.properties/*jdbc.driverClassName=oracle.jdbc.driver.OracleDriverjdbc.url=jdbc:oracle:thin:@127.0.0.1:1521:zwfjdbc.username=11jdbc.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.OracleDriverjdbc.url=jdbc:oracle:thin:@127.0.0.1:1521:zwfjdbc.username=11jdbc.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();          }}


原创粉丝点击