-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathoaapUserDao.java
242 lines (160 loc) · 5.6 KB
/
oaapUserDao.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
package oaapDao;
import oaapDao.*;
import java.util.*;
import java.sql.*;
public class oaapUserDao {
public static Connection getConnection(){
Connection con=null;
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","shubham");
}
catch(Exception e){System.out.println(e);}
return con;
}
public static int oaapUserInfo(String name,String username,String password,String email,String phone){
int status=0;
UserInfoJavaBean uijb=new UserInfoJavaBean();
oaapUserDao oud=new oaapUserDao();
try{
Connection con=oaapUserDao.getConnection();
PreparedStatement ps=con.prepareStatement("insert into oaa_userinfo values (user_id_seq.nextval,?,?,?,?,?)");
ps.setString(2,name);
ps.setString(1,username);
ps.setString(5,password);
ps.setString(3,email);
ps.setString(4,phone);
status=ps.executeUpdate();
con.close();
uijb=oud.oaapUserValidate(username,password);
System.out.println(uijb.getId());
oud.oaapInsertSubjectAccuracy(String.valueOf(uijb.getId()));
}catch(Exception ex){System.out.println(ex);}
return status;
}
public static UserInfoJavaBean oaapUserValidate(String username,String password){
UserInfoJavaBean uijb=new UserInfoJavaBean();
System.out.println("username"+username);
System.out.println("password"+password);
try{ System.out.println("60");
Connection con=oaapUserDao.getConnection();
System.out.println("63");
PreparedStatement preparedstatement=con.prepareStatement("select * from oaa_userinfo where username=? and password=?");
preparedstatement.setString(1,username);
preparedstatement.setString(2,password);
System.out.println("69");
uijb.setStatus(0);
System.out.println("72");
ResultSet resultset=preparedstatement.executeQuery();
System.out.println("75");
if(resultset.next()){
uijb.setStatus(1);
uijb.setId(resultset.getInt(1));
uijb.setName(resultset.getString(3));
uijb.setEmail(resultset.getString(4));
uijb.setPhone("999999");
}
System.out.println("userid="+uijb.getId());
}
catch(Exception ee){
System.out.println(ee);
}
return uijb;
}
public QuestionAnswerJavaBean oaapQuestionFetch(String mock_test_sub,String difficulty,int count){
QuestionAnswerJavaBean qajb=new QuestionAnswerJavaBean();
try{
Connection con=oaapUserDao.getConnection();
PreparedStatement preparedstatement=con.prepareStatement("select * from ooa_"+mock_test_sub+"_"+difficulty+" where sno="+count);
ResultSet resultset=preparedstatement.executeQuery();
if(resultset.next()){
qajb.setStatus(1);
qajb.setQid(resultset.getInt(1));
qajb.setCid(resultset.getInt(2));
qajb.setQuestion(resultset.getString(3));
qajb.setA(resultset.getString(4));
qajb.setB(resultset.getString(5));
qajb.setC(resultset.getString(6));
qajb.setD(resultset.getString(7));
qajb.setAnswer(resultset.getString(8));
System.out.println("if-result-set");
}
System.out.println("test1");
}
catch(Exception ee){
System.out.println(ee);
}
return qajb;
}
public float oaapFetchSubjectAccuracy(String subject,String uid){
float accuracy=0;
try{
Connection con=oaapUserDao.getConnection();
PreparedStatement preparedstatement=con.prepareStatement("select * from ooa_user_stats where userid="+Integer.parseInt(uid));
ResultSet rs=preparedstatement.executeQuery();
if (rs.next())
{
accuracy=rs.getFloat(subject);
}
}
catch(Exception e){
System.out.println(e);
}
return (accuracy);
}
public int oaapInsertSubjectAccuracy(String uid){
int status=0;
try{
Connection con=oaapUserDao.getConnection();
PreparedStatement preparedstatement=con.prepareStatement("insert into ooa_user_stats values(?,0,0,0,0)");
preparedstatement.setInt(1,Integer.parseInt(uid));
status=preparedstatement.executeUpdate();
}
catch(Exception e){
System.out.println(e);
}
return status;
}
public void updateStats(String subject ,String userid ,float accuracy)throws Exception
{
Connection con=oaapUserDao.getConnection();
PreparedStatement ps=con.prepareStatement("update ooa_user_stats set "+subject+"="+accuracy+"where userid="+userid);
ps.executeUpdate();
}
public int selectEmail(String email)
{
int status=0;
try
{
Connection con=oaapUserDao.getConnection();
PreparedStatement preparedstatement=con.prepareStatement("select * from ooa_userinfo where email="+email);
ResultSet rs=preparedstatement.executeQuery();
if (rs.next())
{
status=1;
}
}
catch (Exception e)
{
}
return status;
}
public String selectPass(String email)
{
String pass=null;
try
{
Connection con=oaapUserDao.getConnection();
PreparedStatement preparedstatement=con.prepareStatement("select * from ooa_userinfo where email="+email);
ResultSet rs=preparedstatement.executeQuery();
if(rs.next())
{
pass=rs.getString("PASSWORD");
}
}
catch (Exception e)
{
}
return pass;
}
}