package test;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;
public class Book implements IAction {
private String id;
private String bookname;
private String booktype;
private String author;
private String translator;
private String publisher;
private Date publish_time;
private double price;
private int stock;
public static Connection conn;
public static Statement stmt;
public static ResultSet rs;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getBookname() {
return bookname;
}
public void setBookname(String bookname) {
this.bookname = bookname;
}
public String getBooktype() {
return booktype;
}
public void setBooktype(String booktype) {
this.booktype = booktype;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public String getTranslator() {
return translator;
}
public void setTranslator(String translator) {
this.translator = translator;
}
public String getPublisher() {
return publisher;
}
public void setPublisher(String publisher) {
this.publisher = publisher;
}
public Date getPublish_time() {
return publish_time;
}
public void setPublish_time(Date publish_time) {
this.publish_time = publish_time;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public int getStock() {
return stock;
}
public void setStock(int stock) {
this.stock = stock;
}
@Override
public String toString() {
return "图书编号:" + id + ", 图书名:" + bookname + ", 图书类型:"
+ booktype + ", 作者:" + author
+ ", 翻译:" + translator + ", 出版社:" + publisher + ", 出版时间:"
+ new SimpleDateFormat("yyyy-MM-dd").format(publish_time)
+ ", 价格:" + price + ", 库存:" + stock + ".";
}
public Book() throws SQLException {
}
public Book(String id, String bookname, String booktype,
String author, String translator, String publisher, Date publish_time, double price, int stock) throws SQLException {
this.id = id;
this.bookname = bookname;
this.booktype = booktype;
this.author = author;
this.translator = translator;
this.publisher = publisher;
this.publish_time = publish_time;
this.price = price;
this.stock = stock;
}
@Override
public boolean add() {
boolean flag = false;
Scanner scanner = new Scanner(System.in);
System.out.print("输入图书编号:");
String id = scanner.nextLine();
System.out.print("输入图书名称");
String bookname = scanner.nextLine();
System.out.print("输入图书类别");
String booktype = scanner.nextLine();
System.out.print("输入图书作者");
String author = scanner.nextLine();
System.out.print("输入图书译者");
String translator = scanner.nextLine();
System.out.print("输入图书出版社");
String publisher = scanner.nextLine();
System.out.print("输入图书定价");
double price = scanner.nextDouble();
System.out.print("输入图书库存数量");
int stock = scanner.nextInt();
Date date = new Date();
String insertBookSql = "insert into book values('" + id + "','" + bookname + "','" + booktype + "','" + author + "','" + translator
+ "','" + publisher + "','" + new SimpleDateFormat("yyyy-MM-dd").format(date) + "','" + price + "','" + stock + "')";
try {
conn = JdbcUtils.getConnection();
stmt = conn.createStatement();
int i = stmt.executeUpdate(insertBookSql);
if (i > 0) {
flag = true;
System.out.println(bookname + "已经添加成功");
}
JdbcUtils.closeAll(rs, stmt, conn);
} catch (SQLException e) {
e.printStackTrace();
}
return flag;
}
@Override
public boolean del() {
boolean delFlag = false;
System.out.print("输入你要删除图书的编号:");
String num = new Scanner(System.in).nextLine();
String lookBookSql = "select * from book";
String delBookSql = "delete from book where id='" + num + "'";
try {
conn = JdbcUtils.getConnection();
stmt = conn.createStatement();
rs = stmt.executeQuery(lookBookSql);
while (rs.next()) {
stmt = conn.createStatement();
String id = rs.getString("id");
if (id.equals(num)) {
int i = stmt.executeUpdate(delBookSql);
if (i > 0) {
System.out.println("删除成功!");
delFlag = true;
} else {
System.out.println("删除失败!");
}
}
}
JdbcUtils.closeAll(rs, stmt, conn);
} catch (SQLException e) {
e.printStackTrace();
}
return delFlag;
}
@Override
public int getCount() {
int count = 0;
String countBookSql = "select count(*) from book";
try {
conn = JdbcUtils.getConnection();
stmt = conn.createStatement();
count = stmt.executeUpdate(countBookSql);
System.out.println("总共有:" + count + "本书");
JdbcUtils.closeAll(rs, stmt, conn);
} catch (SQLException e) {
e.printStackTrace();
}
return count;
}
@Override
public void getListInfo() {
String bookInfoSql = "select * from book";
try {
conn = JdbcUtils.getConnection();
stmt = conn.createStatement();
rs = stmt.executeQuery(bookInfoSql);
while (rs.next()) {
String id = rs.getString("id");
String bookname = rs.getString("bookname");
String booktype = rs.getString("booktype");
String author = rs.getString("author");
String translator = rs.getString("translator");
String publisher = rs.getString("publisher");
Date publish_time = rs.getDate("publish_time");
double price = rs.getDouble("price");
int stock = rs.getInt("stock");
Book book = new Book(id, bookname, booktype, author, translator, publisher, publish_time, price, stock);
System.out.println(book.toString());
}
JdbcUtils.closeAll(rs, stmt, conn);
} catch (SQLException ex) {
ex.printStackTrace();
}
}
@Override
public boolean find() {
boolean findFlag = false;
System.out.print("输入你要查询图书的编号:");
String findId = new Scanner(System.in).nextLine();
String lookBookSql = "select * from book";
try {
conn = JdbcUtils.getConnection();
stmt = conn.createStatement();
rs = stmt.executeQuery(lookBookSql);
while (rs.next()) {
String id = rs.g
火飞鹰
- 粉丝: 69
- 资源: 3
最新资源
- 微电源下垂控制matlab仿真建模 采用解耦的电压外环?电流内环控制, 输出电压电流波形质量良好,
- 锂电池充电器用不对称半桥谐振反激变器电路仿真模型 结构简单 效率高 输出电压闭环闭环 原边管子可实现ZVS,副边二极管可实现ZCS 模型内包含开环控制,输出电压闭环控制两种控制方式 matlab
- 异步电机双矢量模型预测转矩控制(MPTC) 针对单矢量MPTC转矩纹波大等缺点,从而引入零矢量组合发波,有效改善转矩控制性能 (1)、双矢量发波(有效电压矢量+零矢量); (2)、仿真系统完善,波形
- 三电平T型逆变器仿真模型 90和60度坐标系都可以 MATLAB Simulink SVPWM控制,无中点电位不平衡控制 具体输出波形见下面图片;与有中点电位平衡的波形基本一样,只是电容电压的区别
- SS2可编程逻辑控制器方案,原创,方案,有源码在手 方案采用ARM芯片M4F内核,主频200M,功能比原装强劲,支持4轴同时可以控制4台伺服电机 同时发脉冲100K 支持U盘更新PLC程序,方便
- 增程式混合动力汽车Cruise整车仿真模型 串联混合动力仿真 1.基于Cruise平台搭建整车部件等动力学模型,基于MATLAB Simulink平台完成整车控制策略的建模,策略模型具备再生制动,最
- 电源开关电源200W 12V 24V,电源架构PFC+LLC+同步整流,高效率高功率因数 转让PCB电路图参数变压器电感参数Bom清单 供学习参考DIY做产品参考设计都非常奈斯 需要的可以直接联
- 该模型采用模型预测控制进行PMSM速度控制,由于预测控制理论在近些年来得到了快速发展并且在工业控制中应用越来越广泛算法应用到永磁同步电机的控制中,充分利用其滚动优化和反馈校正的特点,使控制器表现出较好
- MATLAB机器人仿真 机械臂视觉控制运动仿真,根据设定的跟踪目标,通过读取摄像头跟踪运动目标,利用逆解实现机械臂跟随目标运动的路径规划仿真,实现视觉控制机械臂运动仿真
- 风电并网,matlab,四机两区系统并入风电,风电调频控制
- 高频方波电压注入的的PMSM转子初始位置检测 1.方波电压和正负脉冲电压相结合实现永磁同步电机转子初始位置检测; 2.提供算法对应的参考文献和仿真模型,支持技术解答 仿真模型纯手工搭建,不是从网络上
- 基于空间矢量控制的永磁同步电机状态反馈控制转速系统设计及仿真,仿真平台基于MATLAB Simulink搭建 联系默认发仿真系统文件 另外包含设计文档,高清仿真结果示意图,出图程序 设计文档包括
- Comsol黑磷各向异性吸收
- omron欧姆龙CJ CP程序 欧姆龙CJ2M-CPU35,搭配普洛菲斯触摸屏,主机搭载NC413定位控制模块带将近30轴,NG剔除功能 全自动CE锂电池包装成型机,轴控制,涵盖人机配
- 基于FPGA的图像边缘检测系统设计 边缘检测算子有Sobel和Prewitt算子,本次设计是用按键控制的,可以在Sobel和Prewitt算子间进行切 网上基本没有这种结合的,基本全是Sobel算子
- matlab频谱功率谱画图程序(完整版) 输入:% data为待分析信号,需要是一维实数也能处理数据信息波(例如:下图7-9绘制的导入数据的信号) (感觉信号的横坐标单位可能不太正确,需自行调整一下)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈