ProductDAO.java
上传用户:zhc3n3
上传日期:2022-07-30
资源大小:2750k
文件大小:3k
源码类别:
WEB源码(ASP,PHP,...)
开发平台:
JavaScript
- package com.t11.dao;
- import java.sql.ResultSet;
- import java.util.ArrayList;
- import java.util.List;
- import com.t11.entity.Product;
- import com.t11.entity.Users;
- public class ProductDAO {
- DBUtil dbutil = new DBUtil();
- public boolean insertsProduct(Product product) {
- boolean bool = false;
- String sql = "insert into product values('" + product.getProductname()
- + "'," + product.getProductprice() + ",'"
- + product.getProductimage() + "','"
- + product.getProductauthor() + "','"
- + product.getProductpublishing() + "','"
- + product.getProductintroduction() + "')";
- bool = dbutil.excuUpdate(sql);
- return bool;
- }
- public boolean registerUser(Users user) {
- boolean bools = false;
- String sql = "insert into users values('" + user.getUserName() + "','"
- + user.getPassword() + "')";
- bools = dbutil.excuUpdate(sql);
- return bools;
- }
- public Users UserName(String users) {
- Users user = new Users();
- String sql = "select*from users where username='" + users + "'";
- ResultSet rs = dbutil.excuqury(sql);
- try {
- if (rs != null && rs.next()) {
- user.setUserId(rs.getInt("userid"));
- user.setUserName(rs.getString("username"));
- user.setPassword(rs.getString("userpassword"));
- }
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- // 释放连接
- dbutil.colse(rs);
- }
- return user;
- }
- public List<Product> showProduct(String where) {
- List<Product> list = new ArrayList<Product>();
- String sql = "select*from product" + where;
- ResultSet rs = dbutil.excuqury(sql);
- try {
- while (rs.next()) {
- Product product = new Product();
- product.setProductid(rs.getInt("productid"));
- product.setProductname(rs.getString("productname"));
- product.setProductprice(rs.getDouble("productprice"));
- product.setProductimage(rs.getString("productimage"));
- list.add(product);
- }
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- // 释放连接
- dbutil.colse(rs);
- }
- return list;
- }
- public List<Product> detailedProduct(String where) {
- List<Product> list = new ArrayList<Product>();
- String sql = "select*from product " + where;
- ResultSet rs = dbutil.excuqury(sql);
- try {
- while (rs.next()) {
- Product product = new Product();
- product.setProductid(rs.getInt("productid"));
- product.setProductname(rs.getString("productname"));
- product.setProductprice(rs.getDouble("productprice"));
- product.setProductimage(rs.getString("productimage"));
- product.setProductauthor(rs.getString("productauthor"));
- product.setProductpublishing(rs.getString("productpublishing"));
- product.setProductintroduction(rs.getString("productintroduction"));
- list.add(product);
- }
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- // 释放连接
- dbutil.colse(rs);
- }
- return list;
- }
- }