1、ResourceBundle
ResourceBundle bundle = ResourceBundle.getBundle ( "jdbc" ); // reads the configuration file in the same directory configuration file type, the path is not the same need to add the jdbc.properties
URL = bundle.getString ( "URL");
User = the bundle. the 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");