当前位置:Gxlcms > 数据库问题 > JDBC流操作-父类统一操作

JDBC流操作-父类统一操作

时间:2021-07-01 10:21:17 帮助过:3人阅读

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

}
}

JDBC流操作-父类统一操作

标签:har   public   for   sql语句   print   odi   encoding   结果   prepare   

人气教程排行