首页 > 数据库技术 > 详细

两种读取数据库配置文件的方式

时间:2019-09-16 15:03:50      阅读:94      评论:0      收藏:0      [点我收藏+]

1、ResourceBundle

ResourceBundle bundle = ResourceBundle.getBundle("jdbc"); //读取配置文件 配置文件在类的同一目录下,不同时需要加入路径 jdbc.properties
         url = bundle.getString("url");
         user = bundle.getString("user");
         password = bundle.getString("password");
         driverclass = bundle.getString("driverclass");

2、Properties

Properties properties = new Properties();
        try {
            properties.load(this.getClass().getResourceAsStream("/jdbc.properties"));
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        String driver = properties.getProperty("driver");
        String user = properties.getProperty("user");
        String password = properties.getProperty("password");
        String url = properties.getProperty("url");

两种读取数据库配置文件的方式

原文:https://www.cnblogs.com/agnesFlower/p/11527053.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!