在 MySQL 中建立图书信息表的 sql 语句,图书信息录入、查询的 JSP 代码
时间: 2023-03-01 20:45:03 浏览: 102
MySQL 中建立图书信息表的 SQL 语句如下:
```
CREATE TABLE books (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
author VARCHAR(100) NOT NULL,
publisher VARCHAR(100) NOT NULL,
publish_date DATE NOT NULL,
price DECIMAL(10, 2) NOT NULL
);
```
录入图书信息的 JSP 代码如下:
```
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>录入图书信息</title>
</head>
<body>
<form action="addBook.jsp" method="post">
图书名称:<input type="text" name="name"><br>
作者:<input type="text" name="author"><br>
出版社:<input type="text" name="publisher"><br>
出版日期:<input type="date" name="publish_date"><br>
价格:<input type="text" name="price"><br>
<input type="submit" value="录入">
</form>
</body>
</html>
```
查询图书信息的 JSP 代码如下:
```
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>查询图书信息</title>
</head>
<body>
<table border="1">
<tr>
<th>图书编号</th>
<th>图书名称</th>
<th>作者</th>
<th>出版社</th>
<th>出版日期</th>
<th>价格</th>
</tr>
<%
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
stmt = conn.createStatement();
String sql = "SELECT * FROM books";
rs = stmt.execute