forked from maxliaops/Java_Web_Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCarDao.java
More file actions
79 lines (64 loc) · 1.87 KB
/
CarDao.java
File metadata and controls
79 lines (64 loc) · 1.87 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
71
72
73
74
75
76
77
78
79
package com.dao;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.*;
import com.form.CarForm;
import com.tools.JDBConnection;
public class CarDao {
private JDBConnection connection = null;
public CarDao() {
connection = new JDBConnection();
}
public boolean operationCar(String sql) {
return connection.executeUpdate(sql);
}
public List queryCarList(String sign) {
List list = new ArrayList();
CarForm carForm = null;
String sql=null;
if(sign==null){
sql = "select * from tb_car order by id desc";
}else{
sql = "select * from tb_car where id not in (select car_id from tb_carlog)";
}
ResultSet rs = connection.executeQuery(sql);
try {
while (rs.next()) {
carForm = new CarForm();
carForm.setId(rs.getInt(1));
carForm.setUsername(rs.getString(2));
carForm.setUser_number(rs.getString(3));
carForm.setCar_number(rs.getString(4));
carForm.setTel(rs.getInt(5));
carForm.setAddress(rs.getString(6));
carForm.setCar_road(rs.getString(7));
carForm.setCar_content(rs.getString(8));
list.add(carForm);
}
} catch (SQLException e) {
e.printStackTrace();
}
return list;
}
public CarForm queryCarForm(String id) {
CarForm carForm = null;
String sql = "select * from tb_car where id=" + id + "";
ResultSet rs = connection.executeQuery(sql);
try {
while (rs.next()) {
carForm = new CarForm();
carForm.setId(rs.getInt(1));
carForm.setUsername(rs.getString(2));
carForm.setUser_number(rs.getString(3));
carForm.setCar_number(rs.getString(4));
carForm.setTel(rs.getInt(5));
carForm.setAddress(rs.getString(6));
carForm.setCar_road(rs.getString(7));
carForm.setCar_content(rs.getString(8));
}
} catch (SQLException e) {
e.printStackTrace();
}
return carForm;
}
}