时间:2021-07-01 10:21:17 帮助过:25人阅读
通过一个综合型的例子加深对JDBC操作数据库的增、删、改、查的运用。经典的图书信息录入实例设计数据库CREATETABLE`tb_books`(`id`int(10)unsignedNOTNULLAUTO_I
通过一个综合型的例子加深对JDBC操作数据库的增、删、改、查的运用。
经典的图书信息录入实例
设计数据库
CREATE TABLE `tb_books` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(45) NOT NULL, `price` double NOT NULL, `bookCount` int(10) unsigned NOT NULL, `author` varchar(45) NOT NULL, PRIMARY KEY (`id`) )写一个Book类对图书信息进行封装
package com.lixiyu; public class Book { private int id; private String name; private double price; private int bookCount; private String author; public int getId(){ return id; } public void setId(int id){ this.id=id; } public String getName(){ return name; } public void setName(String name){ this.name=name; } public double getPrice(){ return price; } public void setPrice(double price){ this.price=price; } public int getbookCount(){ return bookCount; } public void setbookCount(int bookCount){ this.bookCount=bookCount; } public String getAuthor(){ return author; } public void setAuthor(String author){ this.author=author; } }添加(insert)图书信息操作
创建AddBook.jsp页面,用于对添加图书信息进行处理
<%@ page language="java" contentType="text/html; charset=GB18030" pageEncoding="GB18030"%> <%@page import="java.sql.Connection"%> <%@page import="java.sql.DriverManager"%> <%@page import="java.sql.PreparedStatement"%>创建insert.jsp,用于创建添加图书信息所需的表单
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>