JDBC流操作-父类统一操作
public class BaseDao {
/** 连接 */
protected Connection con;
/** SQL语句对象 */
protected PreparedStatement ps;
/** 结果集合对象 */
protected ResultSet rs;
/**
* 建立连接
*/
public void setConnection() {
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/myweb(数据库名字)?characterEncoding=utf-8", "root",
"123456");
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 关闭连接
*/
public void closeConnection() {
try {
if (rs != null) {
rs.close();
}
if (ps != null) {
ps.close();
}
if (con != null) {
con.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}