-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathComplaintDetailsDao.java
101 lines (98 loc) · 2.97 KB
/
ComplaintDetailsDao.java
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
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.logging.Level;
import java.util.logging.Logger;
//class ComplaintDetailsDao {
// public static void main(String[] args)
// {
// ComplaintDetailsDao cd = new ComplaintDetailsDao();
// ComplaintDetails cmpd = new ComplaintDetails("Ghopdu","paani ki kami","australia","2015-08-22");
//// System.setProperty("http.proxyPort","3306");
// cd.connect();
// cd.adddetails(cmpd);
// System.out.println("successfully added");
//// System.out.println(cd.getdetails());
// }
//}
class ComplaintDetailsDao
{
Connection con=null;
public void connect()
{
try{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/complaints","root","sql");
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
void adddetails(ComplaintDetails d)
{
try {
String query="insert into fbdata values (?,?,?,?,?,?)";
PreparedStatement pst = con.prepareStatement(query);
pst.setString(1,d.id);
pst.setString(2,d.status);
pst.setString(3,d.name);
pst.setString(4,d.problem);
pst.setString(5,d.location);
pst.setString(6,d.date);
pst.executeUpdate();
}
catch (Exception ex) {
ex.printStackTrace();
}
}
boolean isPresent(String Rid)
{
String query = "select * from fbdata where id = ?";
boolean p=false;
try {
PreparedStatement pst = con.prepareStatement(query);
pst.setString(1, Rid);
ResultSet rs=pst.executeQuery();
System.out.println(rs);
while(rs.next())
{
if(rs.getString("id").equals(Rid))
{
p=true;
break;
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
return p;
}
ComplaintDetails getdetails()
{
ComplaintDetails complaint = new ComplaintDetails();
try
{
String query = "select Name,Problem,Location,Date from fbdata where Name='Ghopdu'" ;
Statement st = con.createStatement();
ResultSet rs=st.executeQuery(query);
rs.next();
String name = rs.getString("1");
String problem = rs.getString("2");
String location = rs.getString("3");
String date = rs.getString("4");
complaint.name=name;
complaint.problem=problem;
complaint.location=location;
complaint.date=date;
}
catch(Exception ex)
{
ex.printStackTrace();
}
return complaint;
}
}