2-14.rar


2-14.rar
资源截图
代码片段和文件信息
package com.lyq.bean;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

/**
 * 商品数据库操作
 *
 */

public class BookDao {
/**
 * 获取数据库连接
 * @return Connection对象
 */
public Connection getConnection(){
// 数据库连接
Connection conn = null;
try {
// 加载数据库驱动,注册到驱动管理器
Class.forName(“com.mysql.jdbc.Driver“);
// 数据库连接字符串
String url = “jdbc:mysql://localhost:3306/db_database10“;
// 数据库用户名
String username = “root“;
// 数据库密码
String password = “111“;
// 创建Connection连接
conn = DriverManager.getConnection(urlusernamepassword);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
// 返回数据库连接
return conn;
}

/**
 * 分页查询所有商品信息
 * @param page 页数
 * @return List
 */
public List find(int page){
// 创建List
List list = new ArrayList();
// 获取数据库连接
Connection conn = getConnection();
// 分页查询的SQL语句
String sql = “select * from tb_product order by id desc limit ??“;
try {
// 获取PreparedStatement
PreparedStatement ps = conn.prepareStatement(sql);
// 对SQL语句中的第1个参数赋值
ps.setInt(1 (page - 1) * Product.PAGE_SIZE);
// 对SQL语句中的第2个参数赋值
ps.setInt(2 Product.PAGE_SIZE);
// 执行查询操作
ResultSet rs = ps.executeQuery();
// 光标向后移动,并判断是否有效
while(rs.next()){
// 实例化Product
Product p = new Product();
// 对id属性赋值
p.setId(rs.getInt(“id“));
// 对name属性赋值
p.setName(rs.getString(“name“));
// 对num属性赋值
p.setNum(rs.getInt(“num“));
// 对price属性赋值
p.setPrice(rs.getDouble(“price“));
// 对unit属性赋值
p.setUnit(rs.getString(“unit“));
// 将Product添加到List集合中
list.add(p);
}
// 关闭ResultSet
rs.close();
// 关闭PreparedStatement
ps.close();
// 关闭Connection
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
return list;
}

/**
 * 查询总记录数
 * @return 总记录数
 */
public int findCount(){
// 总记录数
int count = 0;
// 获取数据库连接
Connection conn = getConnection();
// 查询总记录数SQL语句
String sql = “select count(*) from tb_product“;
try {
// 创建Statement
Statement stmt = conn.createStatement();
// 查询并获取ResultSet
ResultSet rs = stmt.executeQuery(sql);
// 光标向后移动,并判断是否有效
if(rs.next()){
// 对总记录数赋值
count = rs.getInt(1);
}
// 关闭ResultSet
rs.close();
// 关闭Connection
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
// 返回总记录数
return count;
}
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        353  2016-03-21 11:59  第2章2.1index.html

     文件        531  2016-03-21 11:59  第2章2.10index.html

     文件       1101  2016-03-21 11:59  第2章2.11index.html

     文件   20643501  2016-03-21 11:59  第2章2.12Big.ogv

     文件        453  2016-03-21 11:59  第2章2.12index.html

     文件     857894  2016-03-21 11:59  第2章2.12mingrisoft.mp4

     文件        958  2016-03-21 11:59  第2章2.13index.html

     文件        428  2016-03-21 11:59  第2章2.14index.html

     文件        322  2016-03-21 11:59  第2章2.15index.html

     文件        364  2016-03-21 11:59  第2章2.16index.html

     文件        360  2016-03-21 11:59  第2章2.17index.html

     文件        526  2016-03-21 11:59  第2章2.18index.html

     文件        697  2016-03-21 11:59  第2章2.19index.html

     文件        384  2016-03-21 11:59  第2章2.2index.html

     文件        265  2016-03-21 11:59  第2章2.20index.html

     文件        336  2016-03-21 11:59  第2章2.20
ewWindow.html

     文件        422  2016-03-21 11:59  第2章2.3index.html

     文件        424  2016-03-21 11:59  第2章2.4index.html

     文件        259  2016-03-21 11:59  第2章2.5header示例.html

     文件      19156  2016-03-21 11:59  第2章2.5mrlogo.jpg

     文件       4096  2016-03-21 11:59  第2章2.5Thumbs.db

     文件        367  2016-03-21 11:59  第2章2.6index.html

     文件        381  2016-03-21 11:59  第2章2.7index.html

     文件        687  2016-03-21 11:59  第2章2.8index.html

     文件        381  2016-03-21 11:59  第2章2.9index.html

     文件      19917  2016-03-21 11:59  第2章sj1ike.jpg

     文件        380  2016-03-21 11:59  第2章sj1index.html

     文件       5120  2016-03-21 11:59  第2章sj1Thumbs.db

     文件       2957  2016-03-21 11:59  第2章sj2index.html

     文件      51372  2016-03-21 12:01  第2章sj3images1.gif

............此处省略2981个文件信息

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。

发表评论

评论列表(条)