-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPerformanceDAO.java
More file actions
109 lines (102 loc) · 3.77 KB
/
PerformanceDAO.java
File metadata and controls
109 lines (102 loc) · 3.77 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
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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package techquiz.dao;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import javax.swing.JOptionPane;
import techquiz.dbutil.DBConnection;
import techquiz.dto.PerformancePojo;
import techquiz.dto.StudentScorePojo;
/**
*
* @author devanshi
*/
public class PerformanceDAO {
private static Statement st;
static
{
try
{
st=DBConnection.getConnection().createStatement();
}
catch(Exception ex)
{
ex.printStackTrace();
JOptionPane.showMessageDialog(null,"Cannot connect to the DB!");
}
}
public static ArrayList<String> getAllStudentId()throws SQLException
{
ResultSet rs=st.executeQuery("select distinct userid from performance");
ArrayList<String> studentList=new ArrayList<>();
while(rs.next())
{
studentList.add(rs.getString(1));
}
return studentList;
}
//to check when the student visits the score page to check its scores and it might happen that the student havent given any exam yet.
public static ArrayList<String> getAllExamId(String studentId)throws SQLException
{
PreparedStatement ps=DBConnection.getConnection().prepareStatement("select examid from performance where userid=?");
ps.setString(1,studentId);
ResultSet rs=ps.executeQuery();
ArrayList<String> examList=new ArrayList<>();
while(rs.next())
{
examList.add(rs.getString(1));
}
return examList;
}
public static StudentScorePojo getScore(String examId,String studentId)throws SQLException
{
PreparedStatement ps1=DBConnection.getConnection().prepareStatement("select per,language from performance where userid=? and examid=?");
ps1.setString(1,studentId);
ps1.setString(2,examId);
StudentScorePojo obj=new StudentScorePojo();
ResultSet rs=ps1.executeQuery();
if(rs.next())
{
obj.setPerc(rs.getDouble(1));
obj.setLanguage(rs.getString(2));
}
return obj;
}
public static void addPerformance(PerformancePojo performance)throws SQLException
{
PreparedStatement ps2=DBConnection.getConnection().prepareStatement("Insert into performance values(?,?,?,?,?,?,?)");
ps2.setString(1,performance.getUserId());
ps2.setString(2,performance.getExamId());
ps2.setInt(3,performance.getRight());
ps2.setInt(4,performance.getWrong());
ps2.setInt(5,performance.getUnattempted());
ps2.setDouble(6,performance.getPer());
ps2.setString(7,performance.getLanguage());
ps2.executeUpdate();
}
public static ArrayList<PerformancePojo> getAllData()throws SQLException
{
ArrayList<PerformancePojo> performanceList=new ArrayList<>();
Statement st=DBConnection.getConnection().createStatement();
ResultSet rs=st.executeQuery("Select * from perormance");
while(rs.next())
{
PerformancePojo obj=new PerformancePojo();
obj.setUserId(rs.getString(1));
obj.setExamId(rs.getString(2));
obj.setRight(rs.getInt(3));
obj.setWrong(rs.getInt(4));
obj.setUnattempted(rs.getInt(5));
obj.setPer(rs.getDouble(6));
obj.setLanguage(rs.getString(7));
performanceList.add(obj);
}
return performanceList;
}
}