-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstudent.java
More file actions
48 lines (42 loc) · 1.83 KB
/
Copy pathstudent.java
File metadata and controls
48 lines (42 loc) · 1.83 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
import java.sql.*;
import java.util.*;
public class student {
public static void main(String[] args) {
try {
Scanner sc = new Scanner(System.in);
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/data?autoReconnect=true&useSSL=false", "root", "root");
Statement stmt = con.createStatement();
System.out.print("Enter How Many Student : ");
int n = sc.nextInt();
int rollno;
String name;
float CGPA;
PreparedStatement ps = con.prepareStatement("insert into studentCGPA values(?,?,?)");
for (int i = 0; i < n; i++) {
System.out.println("\n\tDetails of Student "+(i+1));
System.out.print("\nEnter Roll No: ");
rollno = sc.nextInt();
System.out.print("Enter Name: ");
name = sc.next();
System.out.print("Enter CGPA: ");
CGPA = sc.nextFloat();
ps.setInt(1, rollno);
ps.setString(2, name);
ps.setFloat(3, CGPA);
ps.executeUpdate();
}
ResultSet rs = stmt.executeQuery("select * from studentCGPA where CGPA > 7;");
System.out.println("\n \t Students who have CGPA greater than 7 ");
while (rs.next())
System.out.println("Roll no : "+rs.getInt(1) + " \t Name : " + rs.getString(2) + "\t CGPA : " + rs.getFloat(3));
System.out.println("Click 1 to clear the table or else click 0 to continue ");
int ch = sc.nextInt();
if(ch == 1)
stmt.executeUpdate("truncate studentCGPA");
sc.close();
} catch (Exception e) {
System.out.println(e);
}
}
}