package com.cn.cx.util;
import com.cn.cx.util.bean.*;
import java.sql.*;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
public class Dao {
static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
static final String DB_URL = "jdbc:mysql://localhost:3306/htuser?useUnicode=true&characterEncoding=UTF-8";
static final String USER = "root";
static final String PASS = "123";
//搜索书的全部信息-----小程序首页全部书籍
public static ArrayList<BookInfo> searchbook() {
Connection conn = null;
Statement stmt = null;
ArrayList<BookInfo> rst = new ArrayList<BookInfo>();
try {
Class.forName(JDBC_DRIVER);
System.out.println("allInfo:正在连接数据库......");
conn = DriverManager.getConnection(DB_URL, USER, PASS);
stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("select book.xuhao,bookname,zongliang,yuliang,sj_number,leixing,image FROM book,book_image where book.xuhao=book_image.xuhao");
ResultSet rs = stmt.executeQuery(sql.toString());
while (rs.next()) {
BookInfo dto = new BookInfo();
dto.setXuhao(rs.getInt("xuhao"));
dto.setBookname(rs.getString("bookname"));
dto.setZongliang(rs.getInt("zongliang"));
dto.setYuliang(rs.getInt("yuliang"));
dto.setSj_number(rs.getString("sj_number"));
dto.setLeixing(rs.getString("leixing"));
dto.setImage(rs.getString("image"));
rst.add(dto);
}
rs.close();
stmt.close();
conn.close();
System.out.println(" allInfo:连接数据库成功......");
} catch (SQLException se) {
se.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (stmt != null) stmt.close();
} catch (SQLException se2) {
}
try {
if (conn != null) conn.close();
} catch (SQLException se) {
se.printStackTrace();
}
}
return rst;
}
//搜索好书信息-----对应小程序活动板块
public static ArrayList<GoodBook> searchgoodbook() {
Connection conn = null;
Statement stmt = null;
ArrayList<GoodBook> rst = new ArrayList<GoodBook>();
try {
Class.forName(JDBC_DRIVER);
System.out.println("goodbook:连接数据库......");
conn = DriverManager.getConnection(DB_URL, USER, PASS);
stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("select * FROM good_book");
ResultSet rs = stmt.executeQuery(sql.toString());
while (rs.next()) {
GoodBook dto = new GoodBook();
dto.setId(rs.getInt("id"));
dto.setTitle(rs.getString("title"));
dto.setUser_id(rs.getString("user_id"));
dto.setUser_content(rs.getString("user_content"));
dto.setTime(rs.getString("time"));
dto.setImage(rs.getString("image"));
rst.add(dto);
}
rs.close();
stmt.close();
conn.close();
System.out.println(" goodbook:连接数据库成功......");
} catch (SQLException se) {
se.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (stmt != null) stmt.close();
} catch (SQLException se2) {
}
try {
if (conn != null) conn.close();
} catch (SQLException se) {
se.printStackTrace();
}
}
return rst;
}
//二维码借书功能-----插入数据表book中
public void insertbook(String xuhao) {
Connection conn = null;
Statement stmt = null;
ArrayList<GoodBook> rst = new ArrayList<GoodBook>();
try {
Class.forName(JDBC_DRIVER);
System.out.println("连接数据库......");
conn = DriverManager.getConnection(DB_URL, USER, PASS);
stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("insert into book(xuhao) values(" + xuhao + ")");
ResultSet rs = stmt.executeQuery(sql.toString());
rs.close();
stmt.close();
conn.close();
System.out.println("连接数据库成功......");
} catch (SQLException se) {
se.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (stmt != null) stmt.close();
} catch (SQLException se2) {
}
try {
if (conn != null) conn.close();
} catch (SQLException se) {
se.printStackTrace();
}
}
return;
}
//通过扫一扫进行显示对应书籍的全部内容
public static ArrayList<BookInfo> saoyisao(String xuhao) {
Connection conn = null;
Statement stmt = null;
ArrayList<BookInfo> rst = new ArrayList<BookInfo>();
try {
Class.forName(JDBC_DRIVER);
System.out.println("saoyisao:连接数据库......");
conn = DriverManager.getConnection(DB_URL, USER, PASS);
stmt = conn.createStatement();
// int shu=Integer.parseInt(xuhao);
StringBuffer sql = new StringBuffer("select book.xuhao,bookname,zongliang,yuliang,sj_number,leixing,image from book,book_image where book.xuhao='" + xuhao + "' and book.xuhao=book_image.xuhao");
ResultSet rs = stmt.executeQuery(sql.toString());
while (rs.next()) {
BookInfo dto = new BookInfo();
dto.setXuhao(rs.getInt("xuhao"));
dto.setBookname(rs.getString("bookname"));
dto.setZongliang(rs.getInt("zongliang"));
dto.setYuliang(rs.getInt("yuliang"));
dto.setSj_number(rs.getString("sj_number"));
dto.setLeixing(rs.getString("leixing"));
dto.setImage(rs.getString("image"));
rst.add(dto);
}
rs.close();
stmt.close();
conn.close();
System.out.println(" saoyisao:连接数据库成功......");
} catch (SQLException se) {
se.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (stmt != null) stmt.close();
} catch (SQLException se2) {
}
try {
if (conn != null) conn.close();
} catch (SQLException se) {
se.printStackTrace();
}
}
return rst;
}
//搜索对应书籍的信息———计算机、数学、中文、外语、护理、体育、经济
public static ArrayList<BookInfo> booktype(String leixing) {
Connection conn = null;
Statement stmt = null;
// ArrayList<BookInfo> rst = new ArrayList<BookInfo>();
ArrayList<BookInfo> rst = new ArrayList<BookInfo>();
try {
Class.forName(JDBC_DRIVER);
System.out.println("booktype:连接数据库......");
conn = DriverManager.getConnection(DB_URL, USER, PASS);
stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("select book.xuhao,bookname,zongliang,yuliang,sj_number,leixing,image from book ,book_image where book.xuhao=book_image.xuhao and leixing='" + leixing + "'");
ResultSet rs = stmt.executeQuery(sql.toSt
小小Java开发者
- 粉丝: 2732
- 资源: 9
最新资源
- 电动汽车空调制冷系统电动压缩机匹配分析1.pdf
- 二氧化碳汽车空调系统设计及研究1.pdf
- 电动汽车驱动系统散热设计与试验验证.pdf
- McQuayDuctSizer(麦克维尔风管尺寸计算软件).zip
- 麦克维尔温湿度分析仪McQuayPsychrometricAnalyzer(hvac-eng.com).zip
- 麦克维尔管道测量仪McQuaypipesizer .zip
- 信捷XC系列PLC主从通讯程序
- 基于蒙特卡洛的电动汽车充电负荷生成
- 基于遗传算法的电动汽车有序充电优化调度 软件:Matlab 利用遗传算法对电动汽车有序充电进行优化;优化目标包括充电费用最低,充电时间达到要求(电动汽车充到足够的电)考虑电动汽车充电对电网负荷的影响
- FPGA 全部verilog代码实现I2C口master端口应用场景 1、FPGA通过I2C口配置TFP410MP 2、EDID配置,FPGA通过I2C口配置AT24C02 AT24C64; 访问地
- Matlab simulink 基于光伏和蓄电池的三端口
- FFT STM32+apFFT程序源代码+lunwen资料+教程讲解 适用于STM32F103平台,使用AD7606同步采集两路正弦信号,内置1024点全相位快速傅里叶变(apFFT)算法,直接计算
- 两电平svpwm算法verilog程序
- 基于改进的快速粒子群有源配电网动态无功优化 软件:Matlab 介绍:在含分布式电源的IEEE33进行无功优化,以无功最优和运行费用最优为目标函数进行优化,采用改进的快速粒子群算法进行计算
- 混合型APF,HAPF,电力牵引系统电能质量控制,高铁谐波补偿,高铁无功补偿,混合型有源电力滤波器,单相SVG,SVG,电力牵引系统谐波无功补偿
- 单机无穷大系统静态稳定性仿真模型
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈