Java中的删除数据库数据的问题

来源:百度知道 编辑:UC知道 时间:2024/06/10 04:49:45
我连接mysql数据库,写了一个方法:
public void deleteCiById(int idpublic void deleteCiById(int id){
String sql = "delete from Computerinfo where id=?";
Query q = session.createQuery(sql);
q.setInteger(0, id);
q.executeUpdate();
session.beginTransaction().commit();
}
我要用另一个类调用这个方法实现删除,用了struts转发框架:
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
// TODO Auto-generated method stub
HttpSession session = request.getSession();
Computerinfo ci = new Computerinfo();
String action = request.getParameter("action");
if(action==null||"".equals(action)){
oper op = new oper();
op.deleteCiById(????????);
return mapping.findForward("succ1");
}
return null;
}
我op.deleteCiById(????????);里面的问号该怎么写?
积分不多了,大虾别见怪!谢谢回答!

你得找个参数接受页面上传过来的id的值,然后把id放到你那个方法里面不就得了

你这个要传个整型参数id,
在struts里就是那个action(你不该用这个变量名),再把action转成整型

op.deleteCiById(Integer.parseInt(action));