利用conn.properties配置文件进行数据库连接
来源:互联网 发布:水仙花数的算法流程图 编辑:程序博客网 时间:2024/05/17 19:57
DbUtil.java
public class DbUtil {private String driver;private String url;private String user;private String pass;public void initPara() throws Exception{Properties props = new Properties();props.load(this.getClass().getResourceAsStream("conn.properties"));driver=props.getProperty("driver"); url = props.getProperty("url"); user = props.getProperty("user"); pass = props.getProperty("pass"); Class.forName(driver);}//建立连接public Connection getCon() throws Exception{this.initPara();Connection con = DriverManager.getConnection(url, user, pass);return con;}//关闭连接public void closeCon(Connection con) throws SQLException{if(con != null){con.close();}}//测试public static void main(String[] args){DbUtil dbUtil = new DbUtil();try {dbUtil.getCon();System.out.println("连接成功!!");} catch (Exception e) {// TODO Auto-generated catch blockSystem.out.println("连接失败!");e.printStackTrace();}}}
driver = com.mysql.jdbc.Driverurl = jdbc:mysql://127.0.0.1:3306/数据库名user = rootpass = 123456
阅读全文
0 0
- 利用conn.properties配置文件进行数据库连接
- jdbc ----利用配置文件进行数据库连接
- 数据库连接的config.properties配置文件
- 数据库连接信息写在properties文件,读取配置文件
- 数据库连接池、读取properties配置文件小结
- 利用Properties讀取配置文件
- 利用HttpServletRequest读取properties配置文件
- django使用配置文件进行数据库连接
- 利用properties进行属性配置
- java中利用properties制作配置文件
- spring利用PropertiesFactoryBean管理属性配置文件properties
- DOM4J 读取XML配置文件进行数据库连接
- Android 利用Properties进行authority管理
- MySql利用properties文件来存放数据库连接信息.ini
- Properties配置文件
- Properties配置文件
- Properties配置文件
- properties配置文件
- 【拜小白opencv】8-感兴趣区域ROI图像获取操作
- kindeditor富文本编辑器配置
- 循环链表实现约瑟夫环(C实现)~
- linux环境下安装redis详细步骤以及配置redis集群详细步骤
- 用户调研需要多少数据
- 利用conn.properties配置文件进行数据库连接
- Bitmap
- HPU 矩阵乘法
- 新手上路系列9:进程间通信
- 牛客网刷题知识点总结(六)java web
- NSArray 冷知识
- 使select option达到超链接的效果实例
- Android PowerImageView实现,可以播放动画的强大ImageView
- python IDE(集成开发环境) pycharm-professional 安装 注册