看资料笔记看到的:
自定义类BaseDAO,用于获取连接,以及关闭资源,为抽象类。(必须会)
public abstract class BaseDAO {
public Connection getConnection() {
Connection conn = null;
try {
// Class.forName("org.gjt.mm.mysql.Driver");
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/employee?user=root&password=123456&useUnicode=true&characterEncoding=utf-8";
conn = DriverManager.getConnection(url);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return conn;
}
public void free(Connection conn, Statement stmt, ResultSet rs) {
try {
if (rs != null) {
rs.close();
}
if (stmt != null) {
stmt.close();
}
if (conn != null) {
conn.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
费解地是为什么要定义成抽象类啊有何意义?普通类不是一样的工具类么???