public class BaseDao {
/** 链接 */
protected Connection con;
/** SQL语句对象 */
protected PreparedStatement ps;
/** 结果集合对象 */
protected ResultSet rs;mysql
/**
* 创建链接
*/
public void setConnection() {web
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();
}sql
}数据库
/**
* 关闭链接
*/
public void closeConnection() {对象
try {
if (rs != null) {
rs.close();
}
if (ps != null) {
ps.close();
}
if (con != null) {
con.close();
}
} catch (Exception e) {
e.printStackTrace();
}utf-8
}
}get