用的IntelliJ IDEA开发的,jdk1.8

1 首先是项目结构,如下图所示

2看各层的代码

首先是web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<servlet>
<servlet-name>book</servlet-name>
<servlet-class>controller.BookController</servlet-class>
<init-param>
<param-name>charSetContent</param-name>
<param-value>utf-8</param-value>
</init-param>
</servlet> <servlet-mapping>
<servlet-name>book</servlet-name>
<url-pattern>/BookController</url-pattern>
</servlet-mapping> </web-app>

接下来是Controller

package controller;

import model.Book;
import net.sf.json.JSONObject;
import service.IBookService;
import serviceImpl.BookService; import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List; /**
* Created by Administrator on 2018/2/2.
*/
public class BookController extends HttpServlet {
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("UTF-8");
String flag = req.getParameter("flag");
String id = req.getParameter("bid");
Integer bid = null;
if (!"".equals(id)) { bid = Integer.parseInt(req.getParameter("bid"));
}
if ("1".equals(flag)) { IBookService bookService = new BookService(); List<Book> book = bookService.selectByPrimaryKey(bid);
req.setAttribute("list", book); req.getRequestDispatcher("jsp/index.jsp").forward(req, resp);
} else if ("2".equals(flag)) {
IBookService bookService = new BookService();
bookService.deleteByPrimaryKey(bid); List<Book> book = bookService.selectByPrimaryKey(null);
req.setAttribute("list", book); req.getRequestDispatcher("jsp/index.jsp").forward(req, resp);
} else if ("3".equals(flag)) {
Double bPrice = Double.parseDouble(req.getParameter("bPrice")); int stock = Integer.parseInt(req.getParameter("stock"));
Book book = new Book();
book.setBid(bid);
book.setbPrice(bPrice);
book.setStock(stock); IBookService bookService = new BookService();
bookService.updateByPrimaryKey(book); List<Book> book1 = bookService.selectByPrimaryKey(null);
req.setAttribute("list", book1); req.getRequestDispatcher("jsp/index.jsp").forward(req, resp);
} else if ("4".equals(flag)) {
String bname = new String(req.getParameter("bname").getBytes("ISO-8859-1"), "UTF-8");
String image = req.getParameter("image");
Double bPrice = Double.parseDouble(req.getParameter("bPrice"));
int stock = Integer.parseInt(req.getParameter("stock"));
Book book = new Book();
book.setBid(bid);
book.setBookname(bname);
book.setImage(image);
book.setbPrice(bPrice);
book.setStock(stock); IBookService bookService = new BookService();
bookService.insert(book); List<Book> book1 = bookService.selectByPrimaryKey(null);
req.setAttribute("list", book1); req.getRequestDispatcher("jsp/index.jsp").forward(req, resp);
} } @Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
doPost(req, resp);
} }

service层

package service;

import model.Book;

import java.util.List;

/**
* Created by Administrator on 2018/2/2.
*/
public interface IBookService {
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table books
*
* @mbggenerated Fri Feb 02 21:32:15 CST 2018
*/
void deleteByPrimaryKey(Integer bid); /**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table books
*
* @mbggenerated Fri Feb 02 21:32:15 CST 2018
*/
void insert(Book record); /**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table books
*
* @mbggenerated Fri Feb 02 21:32:15 CST 2018
*/
void insertSelective(Book record); /**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table books
*
* @mbggenerated Fri Feb 02 21:32:15 CST 2018
*/
List<Book> selectByPrimaryKey(Integer bid); /**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table books
*
* @mbggenerated Fri Feb 02 21:32:15 CST 2018
*/
void updateByPrimaryKeySelective(Book record); /**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table books
*
* @mbggenerated Fri Feb 02 21:32:15 CST 2018
*/
void updateByPrimaryKey(Book record); }
package serviceImpl;

import dao.IBookDao;
import daoImpl.BookDao;
import model.Book;
import service.IBookService; import java.util.List; /**
* Created by Administrator on 2018/2/2.
*/
public class BookService implements IBookService {
IBookDao bookDao = new BookDao(); public void deleteByPrimaryKey(Integer bid) {
bookDao.deleteByPrimaryKey(bid);
} public void insert(Book record) {
bookDao.insert(record);
} public void insertSelective(Book record) {
bookDao.insertSelective(record);
} public List<Book> selectByPrimaryKey(Integer bid) {
List<Book> book = bookDao.selectByPrimaryKey(bid);
return book;
} public void updateByPrimaryKeySelective(Book record) {
bookDao.updateByPrimaryKeySelective(record);
} public void updateByPrimaryKey(Book record) {
bookDao.updateByPrimaryKey(record);
} }

Dao层

package dao;

import model.Book;

import java.util.List;

public interface IBookDao {
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table books
*
* @mbggenerated Fri Feb 02 21:32:15 CST 2018
*/
void deleteByPrimaryKey(Integer bid); /**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table books
*
* @mbggenerated Fri Feb 02 21:32:15 CST 2018
*/
void insert(Book record); /**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table books
*
* @mbggenerated Fri Feb 02 21:32:15 CST 2018
*/
void insertSelective(Book record); /**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table books
*
* @mbggenerated Fri Feb 02 21:32:15 CST 2018
*/
List<Book> selectByPrimaryKey(Integer bid); /**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table books
*
* @mbggenerated Fri Feb 02 21:32:15 CST 2018
*/
void updateByPrimaryKeySelective(Book record); /**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table books
*
* @mbggenerated Fri Feb 02 21:32:15 CST 2018
*/
void updateByPrimaryKey(Book record); }

  

package daoImpl;

import dao.IBookDao;
import model.Book;
import util.DBUtil; import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List; /**
* Created by Administrator on 2018/2/2.
*/
public class BookDao implements IBookDao { ResultSet rs = null;
Connection conn = null;
PreparedStatement pst = null; public List<Book> selectByPrimaryKey(Integer bid) {
String sqlQuery;
if (null == bid || "".equals(bid)) {
sqlQuery = "select * from books";
} else {
sqlQuery = "select * from books where bid=" + bid;
}
List<Book> list = new ArrayList<Book>(); try {
conn = DBUtil.getConnection();
pst = conn.prepareStatement(sqlQuery);
rs = pst.executeQuery(); if (rs != null) {
while (rs.next()) {
int bId = rs.getInt(1);
String bookName = rs.getString(2);
double bPrince = rs.getDouble(3);
String image = rs.getString(4);
int stock = rs.getInt(5); Book book1 = new Book(bId, bookName, bPrince, image, stock);
list.add(book1);
}
} } catch (Exception e) {
e.printStackTrace();
} finally {
DBUtil.release(rs, pst, conn);
} return list;
} public void deleteByPrimaryKey(Integer bid) {
String del = "delete from books where bid=" + bid; try {
conn = DBUtil.getConnection();
pst = conn.prepareStatement(del);
pst.executeUpdate(); } catch (Exception e) {
e.printStackTrace();
} finally {
DBUtil.release(rs, pst, conn);
}
} public void insert(Book record) {
String update = " insert books(bid,bookname,b_price,image,stock) VALUES(" + record.getBid() + ",'" + record.getBookname() + "'," + record.getbPrice() + ",'" + record.getImage() + "'," + record.getStock() + ");"; try {
conn = DBUtil.getConnection();
pst = conn.prepareStatement(update);
pst.executeUpdate(); } catch (Exception e) {
e.printStackTrace();
} finally {
DBUtil.release(rs, pst, conn);
} } public void insertSelective(Book record) { } public void updateByPrimaryKeySelective(Book record) { } public void updateByPrimaryKey(Book record) {
String update = "update books set b_price=" + record.getbPrice() + ",stock=" + record.getStock() + " where bid=" + record.getBid(); try {
conn = DBUtil.getConnection();
pst = conn.prepareStatement(update);
pst.executeUpdate(); } catch (Exception e) {
e.printStackTrace();
} finally {
DBUtil.release(rs, pst, conn);
}
} }

  model

package model;

public class Book {
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database column books.BID
*
* @mbggenerated Fri Feb 02 21:32:15 CST 2018
*/
private Integer bid; /**
* This field was generated by MyBatis Generator.
* This field corresponds to the database column books.BOOKNAME
*
* @mbggenerated Fri Feb 02 21:32:15 CST 2018
*/
private String bookname; /**
* This field was generated by MyBatis Generator.
* This field corresponds to the database column books.B_PRICE
*
* @mbggenerated Fri Feb 02 21:32:15 CST 2018
*/
private Double bPrice; /**
* This field was generated by MyBatis Generator.
* This field corresponds to the database column books.IMAGE
*
* @mbggenerated Fri Feb 02 21:32:15 CST 2018
*/
private String image; /**
* This field was generated by MyBatis Generator.
* This field corresponds to the database column books.STOCK
*
* @mbggenerated Fri Feb 02 21:32:15 CST 2018
*/
private Integer stock; /**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column books.BID
*
* @return the value of books.BID
* @mbggenerated Fri Feb 02 21:32:15 CST 2018
*/
public Integer getBid() {
return bid;
} /**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column books.BID
*
* @param bid the value for books.BID
* @mbggenerated Fri Feb 02 21:32:15 CST 2018
*/
public void setBid(Integer bid) {
this.bid = bid;
} /**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column books.BOOKNAME
*
* @return the value of books.BOOKNAME
* @mbggenerated Fri Feb 02 21:32:15 CST 2018
*/
public String getBookname() {
return bookname;
} /**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column books.BOOKNAME
*
* @param bookname the value for books.BOOKNAME
* @mbggenerated Fri Feb 02 21:32:15 CST 2018
*/
public void setBookname(String bookname) {
this.bookname = bookname == null ? null : bookname.trim();
} /**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column books.B_PRICE
*
* @return the value of books.B_PRICE
* @mbggenerated Fri Feb 02 21:32:15 CST 2018
*/
public Double getbPrice() {
return bPrice;
} /**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column books.B_PRICE
*
* @param bPrice the value for books.B_PRICE
* @mbggenerated Fri Feb 02 21:32:15 CST 2018
*/
public void setbPrice(Double bPrice) {
this.bPrice = bPrice;
} /**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column books.IMAGE
*
* @return the value of books.IMAGE
* @mbggenerated Fri Feb 02 21:32:15 CST 2018
*/
public String getImage() {
return image;
} /**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column books.IMAGE
*
* @param image the value for books.IMAGE
* @mbggenerated Fri Feb 02 21:32:15 CST 2018
*/
public void setImage(String image) {
this.image = image == null ? null : image.trim();
} /**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column books.STOCK
*
* @return the value of books.STOCK
* @mbggenerated Fri Feb 02 21:32:15 CST 2018
*/
public Integer getStock() {
return stock;
} /**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column books.STOCK
*
* @param stock the value for books.STOCK
* @mbggenerated Fri Feb 02 21:32:15 CST 2018
*/
public void setStock(Integer stock) {
this.stock = stock;
} public Book(Integer bid, String bookname, Double bPrice, String image, Integer stock) {
this.bid = bid;
this.bookname = bookname;
this.bPrice = bPrice;
this.image = image;
this.stock = stock;
} public Book() {
}
}

连接数据库util

package util;

import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Properties; /**
* Created by Administrator on 2018/1/7.
*/
public class DBUtil {
private static String driverClassName;
private static String url;
private static String username;
private static String password; static {
//为以上参数赋值 try {
InputStream in = DBUtil.class.getClassLoader().getResourceAsStream("config.properties");
Properties props = new Properties();
props.load(in);
driverClassName = props.getProperty("driverClassName");
url = props.getProperty("url");
username = props.getProperty("username");
password = props.getProperty("password");
Class.forName(driverClassName);
} catch (Exception e) {
throw new RuntimeException(e); } } public static Connection getConnection() throws Exception { return DriverManager.getConnection(url, username, password);
} //释放资源
public static void release(ResultSet rs, Statement stmt, Connection conn) {
if (rs != null) {
try {
rs.close();
} catch (Exception e) {
e.printStackTrace();
}
rs = null;
}
if (stmt != null) {
try {
stmt.close();
} catch (Exception e) {
e.printStackTrace(); }
stmt = null;
} if (conn != null) {
try {
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
conn = null;
} } }

config.properties数据库信息

driverClassName:com.mysql.jdbc.Driver
url:jdbc:mysql://localhost:3306/bookshop
username=root
password=root

  

接着是三个jsp

index.jsp


<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%
String path = request.getContextPath();
request.setAttribute("path", path);
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<html>
<head>
<title>Title</title> <script type="text/javascript" src="${path}/js/jquery.min.js"></script>
</head>
<body>
<form id="form1" method="post" action="">
bookId:<input id="bid" type="text"/>
<input onclick="queryById()" type='button' value="查询"/>
<a href="javascrip:void(0)" onclick="window.open('${path}/jsp/add.jsp?','height=400, width=300')"
>添加</a>
</form>
<table border="1">
<tr id="tId">
<td>bookId</td>
<td>书名</td>
<td>图片</td>
<td>价格</td>
<td>库存</td>
<td>编辑</td>
</tr> <c:forEach items="${list}" var="book"> <tr id="bookId">
<td>${book.bid}</td>
<td>${book.bookname}</td> <td><img src="${book.image}" alt="${book.bookname}"/></td>
<td>${book.bPrice}</td> <td>${book.stock}</td>
<td>
<a href="javascrip:void(0)"
onclick="window.open('${path}/jsp/update.jsp?bid='+${book.bid},'','height=400, width=300')">修改</a> <%--<a href="${path}/jsp/update.jsp" target="_blank" onclick="update(${book.bid})"></a>--%>
<a href="javascript:void(0)" onclick="del(${book.bid})">删除</a> </td>
</tr>
</c:forEach> </table>
</body>
<script type="text/javascript">
function queryById() {
var bid = $('#bid').val(); $("#form1").attr("action", "/BookController?bid=" + bid + "&flag=1"); //$("#form1").action="XXX"; 这种写法是不起作用的!
$("#form1").submit();
}
function del(bid) { $("#form1").attr("action", "/BookController?bid=" + bid + "&flag=2");
$("#form1").submit(); } </script>
</html>
 

add.jsp

<%--
Created by IntelliJ IDEA.
User: Administrator
Date: 2018/2/3
Time: 16:51
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
<script type="text/javascript" src="${path}/js/jquery.min.js"></script>
</head>
<body> <form id="form3" method="post" action=""> <table>
<%String bid = request.getParameter("bid");%> <tr>
<td> bookId:<input id="bid" type="text"/></td>
</tr>
<tr>
<td> 书名:<input id="bname" type="text"/></td>
</tr>
<tr>
<td> 图片:<input id="image" type="text"/></td>
</tr>
<tr>
<td>价格:<input id="bPrice" type="text"/></td>
</tr>
<tr>
<td>库存:<input id="stock" type="text"/></td>
</tr> </table> <input onclick="window.close();" type='button' value="取消"/>
<input onclick="add()" type='button' value="确定"/> </form>
</body>
<script>
<%request.setCharacterEncoding("utf-8");%>
function add() { var bid = $('#bid').val();
var bname = $('#bname').val();
var image = $('#image').val();
var bPrice = $('#bPrice').val();
var stock = $('#stock').val();
$("#form3").attr("action", "/BookController?bid=" + bid + "&bPrice=" + bPrice + "&bname=" + bname + "&image=" + image + "&stock=" + stock + "&flag=4");
$("#form3").submit(); } </script>
</html>

update.jsp

<%--
Created by IntelliJ IDEA.
User: Administrator
Date: 2018/2/3
Time: 16:59
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
<script type="text/javascript" src="${path}/js/jquery.min.js"></script>
</head>
<body> <form id="form2" method="post" action=""> <table>
<%String bid = request.getParameter("bid");%> <tr>
<td> bookId:<input id="bid" type="text" value="<%=bid%>" readonly="true"/></td>
</tr>
<tr>
<td>价格:<input id="bPrice" type="text"/></td>
</tr>
<tr>
<td>库存:<input id="stock" type="text"/></td>
</tr> </table> <input onclick="window.close();" type='button' value="取消"/>
<input onclick="update(<%=bid%>)" type='button' value="确定"/> </form>
</body>
<script>
<%request.setCharacterEncoding("utf-8");%>
function update(bid) { var bPrice = $('#bPrice').val();
var stock = $('#stock').val();
$("#form2").attr("action", "/BookController?bid=" + bid + "&bPrice=" + bPrice + "&stock=" + stock + "&flag=3");
$("#form2").submit(); }
</script>
</html>

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<!-- $Id: pom.xml 642118 2008-03-28 08:04:16Z reinhard $ -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion>
<packaging>war</packaging> <name>Test1</name>
<groupId>com.cyf</groupId>
<artifactId>Test1</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency> <dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.0.8</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency> <dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>RELEASE</version>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.9.3</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>net.sf.ezmorph</groupId>
<artifactId>ezmorph</artifactId>
<version>1.0.6</version>
</dependency>
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.2.3</version>
<classifier>jdk15</classifier><!-- 指定jdk版本 -->
</dependency>
<!-- Json依赖架包下载 --> </dependencies>
<build>
<plugins>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
</plugin>
</plugins>
</build> </project>

sql语句

/*
Navicat MySQL Data Transfer Source Server : test
Source Server Version : 50717
Source Host : localhost:3306
Source Database : bookshop Target Server Type : MYSQL
Target Server Version : 50717
File Encoding : 65001 Date: 2018-02-03 19:12:29
*/ SET FOREIGN_KEY_CHECKS=0; -- ----------------------------
-- Table structure for `books`
-- ----------------------------
DROP TABLE IF EXISTS `books`;
CREATE TABLE `books` (
`BID` int(11) NOT NULL,
`BOOKNAME` varchar(100) NOT NULL,
`B_PRICE` double NOT NULL,
`IMAGE` varchar(200) NOT NULL,
`STOCK` int(11) NOT NULL,
PRIMARY KEY (`BID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- ----------------------------
-- Records of books
-- ----------------------------
INSERT INTO `books` VALUES ('', 'haha', '', 'images/book/book_09.gif', '');
INSERT INTO `books` VALUES ('', '哼哼', '', 'images/book/book_06.gif', '');
INSERT INTO `books` VALUES ('', '钱钟书集', '', 'images/book/book_04.gif', '');
INSERT INTO `books` VALUES ('', '无聊斋', '', 'images/book/book_06.gif', '');
INSERT INTO `books` VALUES ('', '李戡戡乱记', '', 'images/book/book_08.gif', '');
INSERT INTO `books` VALUES ('', '生生世世未了缘', '17.5', 'images/book/book_09.gif', '');
INSERT INTO `books` VALUES ('', '一生有多少爱', '17.5', 'images/book/book_10.gif', '');

访问地址

http://localhost:8080/jsp/index.jsp

注意:由于只是练习一下,校验什么的都没做,各种可能出现的异常也没仔细处理,参考的同学勿喷

jsp+servlet+mysql增删改查的更多相关文章

  1. 最简单的jsp+servlet的增删改查代码

    package ceet.ac.cn.dao; import java.sql.Connection; import java.sql.PreparedStatement; import java.s ...

  2. MySQL—增删改查,分组,连表,limit,union,alter,排序,去重

    MySQL增删改查 在表格的增删改查中,查的内容是最多的,包括group by ,join,limit,union,alter,排序都是服务于查的 #sql语句数据行操作补充 #增加: #insert ...

  3. PHP MySql增删改查

    mysql_connect()连接数据库 mysql_select_db选择数据库 mysql_fetch_assoc()获取结果集 mysql_query()执行sql语句 实例如下: <?p ...

  4. mysql增删改查练习

    Mysql增删改查sql语句练习 关于数据库的一些操作: 进入mysql 命令行: mysql -uroot –p 查看所有数据库: show databases; 创建数据库: create dat ...

  5. Django学习之mysql增删改查

    上节介绍了如何使用命令行操作mysql增删改查,现在介绍如何使用python管理mysql 使用pip 下载完mysql后,mysql会以pymysql模块的形式存储在pycharm的包文件里.我们通 ...

  6. mysql增删改查相关操作

    mysql增删改查相关操作 以前用mysql用的少,对于数据库相关的操作不熟悉,现在开始要接触数据库了,记录一下相关的基础操作吧. 1.数据库的授权操作 # mysql -u root -p Ente ...

  7. 基于gin的golang web开发:mysql增删改查

    Go语言访问mysql数据库需要用到标准库database/sql和mysql的驱动.标准库的Api使用比较繁琐这里再引入另一个库github.com/jmoiron/sqlx. go get git ...

  8. MySQL增删改查的常用语句汇总

    MySQL增删改查的常用语句汇总 以下是总结的mysql的常用语句,欢迎指正和补充~ 一.创建库,删除库,使用库 1.创建数据库:create database 库名; 2.删除数据库:drop da ...

  9. nodejs+express+mysql 增删改查

    之前,一直使用的是nodejs+thinkjs来完成自己所需的项目需求,而对于nodejs中另外一中应用框架express却了解的少之又少,这两天就简单的了解了一下如何使用express来做一些数据库 ...

随机推荐

  1. 对比度受限的自适应直方图均衡化(CLAHE)

    直方图均衡化(HE)是一种很常用的直方图类方法,基本思想是通过图像的灰度分布直方图确定一条映射曲线,用来对图像进行灰度变换,以达到提高图像 对比度的目的.该映射曲线其实就是图像的累计分布直方图(CDF ...

  2. Maximum Subsequence Sum 最大子序列和的进击之路

    本文解决最大子序列和问题,有两个题目组成,第二个题目比第一个要求多一些(其实就是要求输出子序列首尾元素). 01-复杂度1 最大子列和问题   (20分) 给定KK个整数组成的序列{ N1​​, N2 ...

  3. springmvc 获取数组

    spingmvc 获取数据有这几种方式:1.通过HttpRequestServlet的方法获取数据.2.form表单传递对象字段,springmvc自动获取.3.ajax 请求通过注解的方式直接获取数 ...

  4. Python学习 Day 1-简介 安装 Hello world

    简介 Python(英语发音:/ˈpaɪθən/), 是一种面向对象.解释型计算机程序设计语言,由Guido van Rossum于1989年底发明,第一个公开发行版发行于1991年,Python 源 ...

  5. 镜像中的 Everything, GnomeLive ,KdeLive ,livecd ,NetInstall的区别?

    everything: 对完整版安装盘的软件进行补充,集成所有软件 GnomeLive , GNOME桌面版 KdeLive , KDE桌面版 livecd 光盘上运行的系统 ,NetInstall ...

  6. asp IIS网站的配置(Win7下启用IIS7配置ASP运行环境)

    其实win7下的IIS7配置过程是非常简单的.下面让seo博客来详细的介绍一下win7下配置IIS7环境运行ASP网站的方法,以供初接触者参考   第一次在windows7下配置IIS,虽然有丰富的x ...

  7. mycat+ mysql集群 分库分表

    mycat介绍Mycat数据库分库分表中间件国内最活跃的.性能最好的开源数据库中间件!Mycat关键特性关键特性支持SQL92标准支持MySQL.Oracle.DB2.SQL Server.Postg ...

  8. day22-类的封装、property特性以及绑定方法与非绑定方法

    目录 类的封装 两个层面的封装 第一个层面 第二个层面 封装的好处 私有模块 类的propertry特性 setter 和 deleter 类与对象的绑定方法与非绑定方法 类的封装 将类的属性或方法隐 ...

  9. select 修改选中时候的默认默认样式 outline:none 把系统的线关了 然后自己再border一下

    chrome 查看样式的时候默认没有 focus的样式,可以把选择器开开select 修改选中时候的默认默认样式 outline:none 把系统的线关了 然后自己再border一下input:foc ...

  10. Mysql使用遇到的问题(一)

    1.在使用MySQL的时候,已经新建好了表,插入数据的时候报这个错误: Incorrect string value: '\xE5\xAF\x92\xE6\xB1\x9F...' for column ...