JavaWeb之连接Mysql

来源:互联网 发布:美工和平面设计的区别 编辑:程序博客网 时间:2024/05/29 19:06
  • 数据库配置文件
jdbc.driverClass=com.mysql.jdbc.Driverjdbc.url=jdbc:mysql://localhost:3306/seckill?characterEncoding=UTF-8jdbc.user=rootjdbc.password=long
  • 使用
private static Properties properties;    static{        properties=new Properties();            InputStream resourceAsStream = DBUtil.class.getClassLoader()                .getResourceAsStream("db.properties");        try {            properties.load(resourceAsStream);        } catch (IOException e) {            e.printStackTrace();        }    }properties.getProperty("driver") //取值 括号中是属性名
原创粉丝点击