时间:2021-07-01 10:21:17 帮助过:2人阅读
user=root password=root jdbcUrl=jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=UTF-8; driverClass=com.mysql.jdbc.Driver
调用方法:
public void getProperties(){ Properties prop = new Properties(); try { prop.load(new BufferedInputStream(new FileInputStream(this.getClass().getResource("/").getPath().substring(1)+"system.properties"))); System.out.println(prop.getProperty("user")); System.out.println(prop.getProperty("password")); System.out.println(prop.getProperty("jdbcUrl")); System.out.println(prop.getProperty("driverClass")); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
java 通过 Properties 读取数据库配置 .properties 文件的使用。
标签: