-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPercentage.java
More file actions
42 lines (36 loc) · 1.28 KB
/
Percentage.java
File metadata and controls
42 lines (36 loc) · 1.28 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
package TeacherRegister;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.PreparedStatement;
import java.sql.Statement;
public class Percentage {
private Connection connect() throws ClassNotFoundException {
// SQLite connection string
String url = "jdbc:sqlite:C://sqlite/SSSIT.db";
Connection conn = null;
try {
Class.forName("org.sqlite.JDBC");
conn = DriverManager.getConnection(url);
} catch (SQLException e) {
System.out.println(e.getMessage());
}
return conn;
}
public void select(int RollNo) throws ClassNotFoundException{
String sql = "SELECT * FROM Marks WHERE RollNo = ?";
double Percentage = 0;
try {
Connection conn = this.connect();
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setInt(1, RollNo);
ResultSet rs = pstmt.executeQuery();
// loop through the result set
Percentage = rs.getDouble("Marks")/80.0 * 100;
System.out.println("Percentage of "+(rs.getString("Name"))+" is: "+Percentage);
} catch (SQLException e) {
System.out.println(e.getMessage());
}
}
}