JDBC流操做-父類統一操做

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

相關文章
相關標籤/搜索