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 list = new ArrayList(); (f(id)); while(()) { (ing(1)); (f((2))); } String str = "

"; str = str + (0) + "" + (1) + "" + (2) + "
"; ter().print(str); (); (); (); } catch(Exception ex) { tackTrace(); }

}}

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"%>Insert title here

图书ID
图书名字
图书数量
返回到航页

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>Insert title here

请填写要删除图书的ID
图书ID
返回到航页<

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><%@ page import=".*" import=".*" import=".*"%>Insert title here<%try { e(""); Connection con = nection("jdbc:mysql://localhost/tuShu","root","111111"); String sql = "select * from xinXi"; Statement sta = Statement(); ResultSet rs = eQuery(sql); ArrayList list = new ArrayList<>(); while(()) { Book book = new Book(); ((1)); e(ing(2)); kCount((3)); (book); } String str = "

"; for(Book b : list){ str = str + ""; str = str + ""; str = str + ""; } str += "
ID书名数量
" + () + "" + e() + "" + kCount() + "
"; n(str);

(); (); (); } catch(Exception ex) { tackTrace(); }%>

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>Insert title here

请填写要查找图书的ID
图书ID
返回到航页<


本文标签: 图书 失败 填写 茶色 头发