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