读取properties实现数据库连接
来源:互联网 发布:2016高速公路数据分析 编辑:程序博客网 时间:2024/05/20 22:02
读取类
public class ReadProperties {//读取配置文件public String readProperties(String filename,String propertiesname) throws IOException{InputStream in=this.getClass().getClassLoader().getResourceAsStream(filename);Properties prop=new Properties();try{prop.load(in);}catch (IOException e) { e.printStackTrace(); }return prop.getProperty(propertiesname);}}
properties文件
jdbc.driverClassName=com.mysql.jdbc.Driverjdbc.url=jdbc:mysql://localhost:3306/testjdbc.username=testjdbc.password=123456
数据库连接代码
public Connection getConnection()throws Exception{ReadProperties rp=new ReadProperties();String filename="database.properties";String driver=rp.readProperties(filename, "jdbc.driverClassName");String url=rp.readProperties(filename, "jdbc.url");String username=rp.readProperties(filename,"jdbc.username");String password=rp.readProperties(filename,"jdbc.password");Connection conn=null;//加载驱动System.out.println(driver);Class.forName(driver);conn=DriverManager.getConnection(url,username,password);//return conn;}
阅读全文
0 0
- 读取properties实现数据库连接
- 数据库连接信息写在properties文件,读取配置文件
- 数据库连接池、读取properties配置文件小结
- 实现编码方式读取properties
- jdbc中从properties文件中读取数据库连接字符串
- ServletContext实现转发和读取Properties配置文件
- java实现读取.properties的键值
- ServletContext实现转发和读取Properties配置文件
- 通过dom4j读取xml实现数据库连接
- Properties读取properties文件
- Properties 读取 Properties文件
- .properties读取
- properties读取
- 读取Properties
- 数据库连接,读取
- 数据库连接 properties文件配置
- hibernate.properties数据库连接配置
- 2.通过原始的Driver接口通过读取Properties属性文件获取JDBC数据库连接Connection
- CSU-ACM2017暑假集训2-二分搜索 poj-2785-4 Values whose Sum is 0
- sequenceFile 转换,并导入至hbase中 (图文解说 2017-7-23)
- GIMMS NDVI 3g V1.0 数据
- Android 性能优化
- odoo导入关联表的数据
- 读取properties实现数据库连接
- Linux环境使用Nexus搭建Maven私服
- c++ 运算符优先级:
- Fine-Grained Classification之车型识别
- 进程、线程间通信机制
- spring mvc 4.1支持protobuf converters
- CNN卷积神经网络全面生动解读-深度学习笔记
- python相关知识总结
- MyBatis 自动构建