資源描述:
《javaweb-連接mysql數(shù)據(jù)庫增刪改查》由會員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫。
1、連接MYSQL數(shù)據(jù)庫的簡單增刪改查項(xiàng)目框架如圖所示:所需工具:所需工具:所需工具:所需工具:程序代碼:packagecom.user.action;importjava.io.IOException;importjavax.servlet.ServletException;importjavax.servlet.http.HttpServlet;importjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpServletResponse
2、;importcom.user.bean.UserBean;importcom.user.dao.UserDao;publicclassInsertOrUpdateActionextendsHttpServlet{/****/privatestaticfinallongserialVersionUID=1L;privateUserDaouserDao;publicvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletEx
3、ception,IOException{doPost(request,response);}publicvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{request.setCharacterEncoding("utf-8");response.setCharacterEncoding("utf-8");userDao=newUserDao();Stringstr=re
4、quest.getRequestURI();str=str.substring(str.lastIndexOf("/")+1);Stringyx=request.getParameter("yx");Stringzy=request.getParameter("zy");Stringage=request.getParameter("age");Stringdh=request.getParameter("dh");Stringqq=request.getParameter("qq");Stringsex=reques
5、t.getParameter("sex");UserBeanuserBean=newUserBean();userBean.setYx(yx);userBean.setZy(zy);if(!"".equals(age)&&age!=null){userBean.setAge(Integer.valueOf(age));}else{userBean.setAge(0);}userBean.setDh(dh);userBean.setQq(qq);userBean.setSex(sex);if("InsertUserAct
6、ion".equals(str)){if(userDao.insertUser(userBean)){response.sendRedirect("SelectAllUser");}else{response.sendRedirect("SelectAllUser");}}elseif("UpdateUserAction".equals(str)){StringstrId=request.getParameter("id");if(!"".equals(strId)&&strId!=null){userBean.set
7、Id(Integer.valueOf(strId));}else{userBean.setId(-1);}if(userDao.updateUser(userBean)){response.sendRedirect("SelectAllUser");}else{response.sendRedirect("SelectAllUser");}}}}packagecom.user.action;importjava.io.IOException;importjavax.servlet.ServletException;im
8、portjavax.servlet.http.HttpServlet;importjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpServletResponse;publicclassLoginActionextendsHttpServlet{/