jdbc.properties,以及读取配置信息(CSDN内转帖)

driverClassName=org.gjt.mm.mysql.Driver
url=jdbc:mysql://localhost:3306/itcast_test?useUnicode=true&characterEncoding=UTF-8
username=root
password=root
initialSize=1
maxActive=100
maxIdle=8
minIdle=1

 

 

public void getValue() { //System.out.println("..//"+System.getProperty("user.dir")+"//webapps"); try { String path = this.getClass().getClassLoader().getResource("/").getPath(); String url = path.replaceAll("%20", " "); FileInputStream fis = new FileInputStream(url+"config.properties"); Properties prop = System.getProperties(); try { prop.load(fis); //赋值 this.DRIVER = prop.getProperty("driver"); this.URL = prop.getProperty("url"); this.USER = prop.getProperty("user"); this.PASSWORD =prop.getProperty("password"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } }

 

 

转载自http://blog.csdn.net/maqingbin8888/archive/2009/04/12/4066190.aspx

 

你可能感兴趣的:(mysql,properties,String,jdbc,url,Path)