首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

hibernate 施行sql语句

2012-08-30 
hibernate 执行sql语句daoprotected Connection con nullprotected PreparedStatement ps nullprote

hibernate 执行sql语句
dao
protected Connection con = null;
protected PreparedStatement ps = null;
protected ResultSet rs = null;
/**
* 执行SQL语句
*
* @param strSql
* @author goupan
*/
public void executeSql(String strSql) {
try {
con = getConnection();
ps = con.prepareStatement(strSql);

ps.execute();
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
closeStatement();
closeConnection();
} catch (Exception e) {
e.printStackTrace();
}
}
}
/**
* 取得连接
*
* @return
*/
public Connection getConnection() {
return this.getSession().connection();
}

/**
* 关闭连接
*
* @throws Exception
*/
public void closeConnection() throws Exception {
if (con != null) {
con.close();
}
}

public void closeStatement() throws Exception {
if (ps != null) {
ps.close();
}
}

public void closeResultSet() throws Exception {
if (rs != null) {
rs.close();
}
}

/**
* 执行SQL语句
*
* @param strSql
* @author goupan
*/
public void executeSql(String strSql) {
try {
con = getConnection();
ps = con.prepareStatement(strSql);

ps.execute();
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
closeStatement();
closeConnection();
} catch (Exception e) {
e.printStackTrace();
}
}
}
/**
* 取得连接
*
* @return
*/
public Connection getConnection() {
return this.getSession().connection();
}

/**
* 关闭连接
*
* @throws Exception
*/
public void closeConnection() throws Exception {
if (con != null) {
con.close();
}
}

public void closeStatement() throws Exception {
if (ps != null) {
ps.close();
}
}

public void closeResultSet() throws Exception {
if (rs != null) {
rs.close();
}
}

热点排行