发表于: 2017-04-15 00:19:19
2 1431
今天做的事:
1、编写了DBUtil工具类
package DAO;
import java.sql.*;
/**
* Created by wei on 2017/4/14.
*/
public class DBUtil {
//获取数据库连接
public static Connection getConnection(){
Connection connect = null;
try {
Class.forName("com.mysql.jdbc.Driver");
connect = DriverManager.getConnection("jdbc:mysql://localhost:3306/wei/demo","root","1234");
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return connect;
}
//关闭数据连接
public static void closeAll(ResultSet set, Statement statement,Connection connection){
//检测到连接的存在就关闭
try {
if (set != null){
set.close();
}
if (statement != null ){
statement.close();
}
if (connection != null){
connection.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
疑问:为何获取数据库连接的时候要使用动态类?
2、对Junit进行了一些基本的了解
明天要做的事:用Junit编写单元测试代码
评论