JDBC stream operations - the parent class unified operation

BaseDao {class public
/ connection ** * /
protected Connection CON;
/ ** the SQL statement object * /
protected the PreparedStatement PS;
/ ** result set objects * /
protected the ResultSet RS;

/ **
* establish a connection
* /
public the setConnection void () {

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();
}

}

/ **
* close connection
* /
public void closeConnection () {

try {
if (rs != null) {
rs.close();
}
if (ps != null) {
ps.close();
}
if (con != null) {
con.close();
}
} catch (Exception e) {
e.printStackTrace();
}

}
}

Guess you like

Origin www.cnblogs.com/wind-copy1234/p/11793964.html