1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
| package com.hgu.fruit.dao;
import com.hgu.fruit.dao.inter.FruitDAO; import com.hgu.fruit.pojo.Fruit;
import java.sql.Connection; import java.util.ArrayList;
public class FruitImp extends BaseDao<Fruit> implements FruitDAO { @Override public void insert(Connection connection, Fruit fruit) { String sql = "INSERT INTO FRUIT(name, price, count, remark) VALUES(?,?,?,?)"; upDate(connection, sql,fruit.getFname(), fruit.getFprice(), fruit.getFcount(), fruit.getRemark()); }
@Override public void update(Connection connection, Fruit fruit) { String sql = "UPDATE FRUIT SET name = ?, price = ?, count = ?, remark = ? WHERE ID = ?"; upDate(connection, sql, fruit.getFname(), fruit.getFprice(), fruit.getFcount(), fruit.getRemark(), fruit.getFid()); }
@Override public void deleteByID(Connection connection, int id) { String sql = "DELETE FROM FRUIT WHERE ID = ?"; upDate(connection, sql, id); }
@Override public Fruit getFruitByID(Connection connection, int id) { String sql = "SELECT id as fid, name as fname, price fprice, count fcount, remark remark FROM FRUIT WHERE ID = ?"; Fruit fruit = searchInstance(connection, sql, id); return fruit; }
@Override public ArrayList<Fruit> getAll(Connection connection) { String sql = "SELECT id as fid, name as fname, price fprice, count fcount, remark remark FROM FRUIT"; ArrayList<Fruit> fruits = searchList(connection, sql); return fruits; }
@Override public ArrayList<Fruit> getFruitPage(Connection connection, int pageNumber) { String sql = "SELECT id as fid, name as fname, price fprice, count fcount, remark remark FROM FRUIT LIMIT ?, 5"; ArrayList<Fruit> fruits = searchList(connection, sql, 5 * (pageNumber - 1)); return fruits; }
@Override public int getCount(Connection connection) { String sql = "SELECT COUNT(*) FROM FRUIT"; int count = Integer.parseInt(getValue(connection, sql).toString()); return count; }
@Override public ArrayList<Fruit> getKeyValueFruit(Connection connection, String kv, int pageNumber) { StringBuffer stringBuffer = new StringBuffer(); stringBuffer.append("%"); for (int i = 0; i < kv.length(); i++) { stringBuffer.append(kv.charAt(i)+"%"); } String s = stringBuffer.toString(); String sql = "SELECT id as fid, name as fname, price fprice, count fcount, remark remark FROM FRUIT WHERE name LIKE ? LIMIT ?, 5"; ArrayList<Fruit> fruits = searchKeyValue(connection, sql, s, (pageNumber-1)*5); return fruits; }
@Override public int getKeyValueCount(Connection connection, String kv) { StringBuffer stringBuffer = new StringBuffer(); stringBuffer.append("%"); for (int i = 0; i < kv.length(); i++) { stringBuffer.append(kv.charAt(i)+"%"); } String s = stringBuffer.toString(); String sql = "SELECT COUNT(*) FROM FRUIT WHERE name LIKE ? "; int count = Integer.parseInt(getValue(connection, sql, s).toString()); return count; } }
|