Properties的使用
来源:互联网 发布:淘宝模特神速拍照 编辑:程序博客网 时间:2024/05/22 21:44
package testDB;import java.io.InputStream;import java.sql.Connection;import java.sql.Driver;import java.sql.DriverManager;import java.util.Properties;public class TestDB {public static void main(String[] args) throws Exception {Properties properties = new Properties();InputStream is = properties.getClass().getResourceAsStream("/database.properties");properties.load(is);is.close();String driver = properties.getProperty("driver");System.out.println(driver);String dburl = properties.getProperty("jdbcUrl");System.out.println(dburl);String user = properties.getProperty("user");System.out.println(user);String password = properties.getProperty("password");System.out.println(password);Driver drv = (Driver) Class.forName(driver).newInstance(); DriverManager.registerDriver(drv); Connection con = DriverManager.getConnection(dburl,user, password);if(con!=null){System.out.println("connection ok");}con.close();}}
database.properties
driver=com.mysql.jdbc.DriverjdbcUrl=jdbc\:mysql\://localhost\:3306/springmvc?useUnicode\=true&characterEncoding\=utf8user=rootpassword=root
0 0
- 使用JAVA的Properties
- Properties 类的使用
- Properties 类的使用
- log4j.properties的使用
- properties类的使用
- 配置文件properties的使用
- properties文件的使用
- Properties的使用
- 档案文件properties的使用
- Properties的使用
- Properties类的使用
- android Properties的使用
- Properties的使用
- Properties对象的使用
- Properties的使用
- Properties的使用
- Properties类的使用
- Properties的基本使用
- WM_KEYDOWN和键盘响应
- Spark 性能相关参数配置详解-压缩与序列化篇
- 字符串函数sprintf / sprintf_s的陷阱
- sql server数据表转换成xml
- 二叉树中何为某一值的路径实现
- Properties的使用
- <chrono> <TCLAP>与<CImg>
- Android系统亮屏、锁屏、屏幕解锁事件(解决部分手机亮屏后未解锁即进入resume状态)
- 卸载了WebStorm
- Centos安装mysql
- Php面向对象 – Final类
- notifyDataSetInvalidated()和notifyDataSetChanged()的区别!
- java ClassLoad详解
- xmpp ios 问题篇