使用场景:
- 对数据库进行连接,执行sql更新数据库数据
- 使用配置文件设置数据库连接信息,方便日后操作其他数据库
实现:
- (1)新建一个配置文件mysql.properties,放在src目录下
mysql.properties具体内容
- (2)新建一个Mysqlread类专门写读配置文件的内容,新建一个MysqlOperation类专门连接数据库和断开数据库
public class Mysqlread {
public static final String [] message=readurl();
private static String[] readurl() {
Properties prop=new Properties();
String [] message=new String[4];
int i=0;
try {
InputStream in=new BufferedInputStream(new FileInputStream("src/mysql.properties"));
prop.load(in);
me