`
activemq
  • 浏览: 26474 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

java 与 读取 .properties文件

阅读更多

sqlcon.properties配置文件 连接数据库
driver=com.microsoft.jdbc.sqlserver.SQLServerDriver
url=jdbc:microsoft:sqlserver://127.0.0.1:1433;databasename=pubs
uid=sa
pwd=

public class Dbcon {

private Properties p=null;
private Connection con=null;

public Dbcon(){
p=new Properties();
}

public Connection getcon(){
try {

p.load(this.getClass().getResourceAsStream("sqlcon.properties"));
Class.forName(p.getProperty("driver"));
this.con=DriverManager.getConnection(p.getProperty("url"),p.getProperty("uid"),p.getProperty("pwd"));
if(con!=null){
return con;
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}

public void closecon(Connection con){
try {
con.close();
} catch (Exception e) {
e.printStackTrace();
}

}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics