buat form di insert.jsp
buat servletdengan nama Cari
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Database db=new Database();
RequestDispatcher dis=null;
HttpSession session=request.getSession();
String id=request.getParameter("id");
String judul=request.getParameter("judul");
String pengarang=request.getParameter("pengarang");
String penerbit=request.getParameter("penerbit");
String kategori=request.getParameter("kategori");
String sql1="insert into databuku value('"+id+"','"+judul+"','"+pengarang+"','"+penerbit+"','"+kategori+"')";
Statement st=null;
try {
st = db.getConnection().createStatement();
} catch (SQLException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
try {
st.executeUpdate(sql1);
session.setAttribute("pesan", "Data telah tersimpan");
dis=request.getRequestDispatcher("admin.jsp");
dis.forward(request, response);
} catch (SQLException e) {
session.setAttribute("pesan","Data gagal tersimpan");
dis=request.getRequestDispatcher("insert.jsp");
dis.forward(request, response);
e.printStackTrace();
}
}
ps: Database yang di gunakan adalah database yg sama pd postingan sebelumnya!!
No comments:
Post a Comment