admin 管理员组文章数量: 887021
2024年1月13日发(作者:墨茶色头发好看吗)
package ;public class Book { private int id; private String name; private int bookCount;
public int getId() {return id;} public String getName() {return name;} public int getBookCount() {return bookCount;}
public void setId(int id) { = id;} public void setName(String name) { = name;} public void setBookCount(int bookCount) {unt = bookCount;}}
package Servlet;import ption;import tException;import vlet;import rvlet;import rvletRequest;import rvletResponse;import .*;/** * Servlet implementation class AddServlet */@WebServlet("/AddServlet")public class AddServlet extends HttpServlet {
/** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub //ter().append("Served at: ").append(textPath());
racterEncoding("utf-8");
int id = f(ameter("id")); String name = ameter("bookName"); int bookCount = f(ameter("bookCount")); try{ e(""); Connection con = nection("jdbc:mysql://localhost/tuShu","root","111111"); String sql = "insert into xinXi(id, name, bookCount) values(?, ?, ?)"; PreparedStatement pr = eStatement(sql);
(1, id); ing(2, name); (3, bookCount); int row = eUpdate();
String str = "成功添加" + row + "条数据!";
if(row > 0){ ter().print(str); } else { ter().print("添加失败!"); } (); (); } catch(Exception ex){ ter().print("失败!"); tackTrace(); } }}
package Servlet;import .*;import ption;import tException;import vlet;import rvlet;import rvletRequest;import rvletResponse;/** * Servlet implementation class DeleteServlet */@WebServlet("/DeleteServlet")public class DeleteServlet extends HttpServlet { /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub //ter().append("Served at: ").append(textPath());
racterEncoding("UTF-8"); int id = f(ameter("id"));
try{ e(""); Connection con = nection("jdbc:mysql://localhost/tuShu","root","111111"); String sql = "delete from xinXi where id=?"; PreparedStatement pr = eStatement(sql); (1,id); int row = eUpdate(); String str = "成功删除" + row + "条数据!"; if(row > 0){ ter().print(str); } else { ter().print("删除失败!"); } (); (); } catch(Exception ex){ ter().print("失败!"); tackTrace(); } }}
package Servlet;import ption;import tion;import Manager;import Set;import ent;import ist;import ;import tException;import vlet;import rvlet;import rvletRequest;import rvletResponse;/** * Servlet implementation class FindOneServlet */@WebServlet("/FindOneServlet")public class FindOneServlet extends HttpServlet { /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub //ter().append("Served at: ").append(textPath());
racterEncoding("UTF-8"); int id = f(ameter("id")); try { e(""); Connection con = nection("jdbc:mysql://localhost/tuShu","root","111111"); Statement sta = Statement(); String sql = "select name, bookCount from xinXi where id=" + id; ResultSet rs = eQuery(sql); List
"; ter().print(str); (); (); (); } catch(Exception ex) { tackTrace(); } "; str = str + (0) + " " + (1) + " " + (2) + "
}}
package Servlet;import ption;import tion;import Manager;import edStatement;import tException;import vlet;import rvlet;import rvletRequest;import rvletResponse;/** * Servlet implementation class UpdateServlet */@WebServlet("/UpdateServlet")public class UpdateServlet extends HttpServlet {
/** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { racterEncoding("utf-8");
int id = f(ameter("id")); int bookCount = f(ameter("bookCount")); try { e(""); Connection con = nection("jdbc:mysql://localhost/tuShu","root","111111"); String sql = "update xinXi set bookCount=? where id=?"; PreparedStatement pr = eStatement(sql); (1,bookCount); (2, id); int row = eUpdate(); String str = "成功修改" + row + "条数据!"; if(row > 0){ ter().print(str); } else { ter().print("修改失败!"); } (); (); (); (); } catch(Exception ex) { tackTrace(); }
}}
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
图书ID | |
图书名字 | |
图书数量 |
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
请填写要删除图书的ID | |
图书ID | |
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><%@ page import=".*" import=".*" import=".*"%>
ID | 书名 | 数量 |
" + () + " | "; str = str + "" + e() + " | "; str = str + "" + kCount() + " |
(); (); (); } catch(Exception ex) { tackTrace(); }%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
请填写要查找图书的ID | |
图书ID | |
版权声明:本文标题:JSP+Servlet+jQuery实现简单的MySQL数据库的增、删、改、查 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.freenas.com.cn/free/1705088226h472722.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论