
EmployeeDao.java
//删除数据
public boolean deleteEmployeeById(int id){
boolean result = false
try{
con = DBCon.getConn()
String sql = "delete from tb_employee where id=?"
pstmt = (PreparedStatement) con.prepareStatement(sql)
pstmt.setInt(1, id)
int i = pstmt.executeUpdate()
if(i == 1)
result = true
}catch(Exception e){
e.printStackTrace()
}finally{
try{
if(pstmt != null){
pstmt.close()
}
}catch(Exception e){
e.printStackTrace()
}
try{
if(con != null){
con.close()
}
}catch(Exception e){
e.printStackTrace()
}
}
return result
}
TestSql2.java
package com.sql.test
import com.sql.dao.EmployeeDao
public class TestSql02 {
public static void main(String[] args){
boolean result = EmployeeDao.getInstance().deleteEmployeeById(1)
if(result == true){
System.out.println("删除成功!")
}else{
System.out.println("删除失败!")
}
}
}
可以使用HibernateTemplate执行Hql语句 *** 作。
String userId = "somebody"String hql ="delete from ATable as a where a.userId = "+ userId +""
this.getHibernateTemplate().bulkUpdate(queryString)
你可以给按钮配置方法,方法去实现连接数据库,然后删除你需要删除的信息。然后,给按钮配置方法的话,需要前台的按钮和后台的代码连接,可以使用Servlet或者Struts的Action等方式。你的这个问题不是一下子能说清楚的,因为涉及到的模块比较多,你问得比较宽泛。你要是全部都不熟悉的话,可能要花点时间。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)