forked from maxliaops/Java_Web_Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGoodsDaoImpl.java
More file actions
70 lines (62 loc) · 1.59 KB
/
GoodsDaoImpl.java
File metadata and controls
70 lines (62 loc) · 1.59 KB
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
package com.dao;
import com.model.Goods;
import com.tools.ChStr;
import com.tools.ConnDB;
public class GoodsDaoImpl implements GoodsDao {
ConnDB conn = new ConnDB();
ChStr chStr = new ChStr();
public int insert(Goods g) {
int ret = -1;
try {
String sql = "Insert into tb_goods (TypeID,GoodsName,Introduce,Price,nowPrice,picture,newgoods,sale) values("
+ g.getTypeID()
+ ",'"
+ chStr.chStr(g.getGoodsName())
+ "','"
+ chStr.chStr(g.getIntroduce())
+ "',"
+ g.getPrice()
+ ","
+ g.getPrice()
+ ",'"
+ chStr.chStr(g.getPicture())
+ "',"
+ g.getNewGoods()
+ "," + g.getSale() + ")";
ret = conn.executeUpdate(sql);
} catch (Exception e) {
ret = 0;
}
conn.close();
return ret;
}
public int update(Goods g) {
int ret = -1;
try {
String sql = "update tb_Goods set TypeID=" + g.getTypeID()
+ ",GoodsName='" + chStr.chStr(g.getGoodsName())
+ "',introduce='" + chStr.chStr(g.getIntroduce())
+ "',price=" + g.getPrice() + ",nowprice="
+ g.getNowPrice() + ",picture='"
+ chStr.chStr(g.getPicture()) + "',newgoods="
+ g.getNewGoods() + ",sale=" + g.getSale() + " where ID="
+ g.getID();
ret = conn.executeUpdate(sql);
} catch (Exception e) {
ret = 0;
}
conn.close();
return ret;
}
public int delete(Goods g) {
int ret = -1;
try {
String sql = "Delete from tb_goods where ID=" + g.getID();
ret = conn.executeUpdate(sql);
} catch (Exception e) {
ret = 0;
}
conn.close();
return ret;
}
}